Last active
December 14, 2015 19:59
-
-
Save jaapie/5140328 to your computer and use it in GitHub Desktop.
A shell function for Bash that goes up a specified number of directory levels. Easier than typing `cd ../../../` etc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
function up () { | |
levels=$1 | |
if [ -z "$levels" ]; then | |
levels=1 | |
fi | |
# Test if $levels is a number; the -eq operator expects a number, and will | |
# output an error if one is not found. Any output the STDERR is redirected | |
# to the bit bucket (/dev/null) | |
if [ "$levels" -eq "$levels" ] 2> /dev/null; then | |
if [ "$levels" -eq "0" ]; then | |
levels=1 | |
fi | |
for (( c=1; c<=levels; c++ )) | |
do | |
cd ../ | |
done | |
else | |
echo up: expected a number, not $levels | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment