Bash: manipulating with strings (percent sign)

If you use @fedorqui’s resource, you’ll see it is going to strip the shortest match of /* from the end of the first positional argument. An example:

    echo ${1%/*}

example_foo path/to/directory/sub_directory
# => path/to/directory

In the example I used the second positional argument since the first is the name of the function.

Leave a Comment