Good day how to remove all the variables in the last slash in bash.
#!/bin/bash
VAR="/foo/bar/abcd ef gh"
I need to remove: abcd ef gh
path /foo/bar/ is always different
Seeking short notation ;-) thank you..
If your $VAR is always a path to a dir/file, you can use this:
$ VAR=$(dirname "$VAR")
$ echo $VAR
/foo/bar
Update: You can also use parameter substitution in bash:
$ echo ${VAR%/*}
/foo/bar
/foo or foo - dirname turns them into / and ., respectively, while parameter replacement empties the first and leaves the second alone.