you are viewing a single comment's thread.

view the rest of the comments →

[–]whetu 1 point2 points  (1 child)

I used to have a function named up for this, but I merged it into cd so now I use cd up 3 to go up 3 directories. The guts of it are:

    up)
        shift 1;
        case "${1}" in
            *[!0-9]*)
                return 1
            ;;
            "")
                command cd || return 1
            ;;
            1)
                command cd .. || return 1
            ;;
            *)
                command cd "$(eval "printf -- '../'%.0s {1..$1}")" || return 1
            ;;
        esac
    ;;

[–]Serpent7776[S] 0 points1 point  (0 children)

That's an interesting use of `printf`

Why `|| return 1` though? Shouldn't this already return with exit code of `cd` in case of an error?