3 ms·
Yeah, I couldn't make that work for me (on Linux or MacOS) .. although I'd love it if there were a way to quickly get 'just the directory' or 'just the filename
by mmjaa 9y ago
Yeah, I couldn't make that work for me (on Linux or MacOS) .. although I'd love it if there were a way to quickly get 'just the directory' or 'just the filename' in bash with a shortcut, instead of having to resort to $(dirname blah) and so on .. I'm sure there is some way but :h doesn't look to be the shortcut as expected.
- lloeki 9y agoAssuming blah is in a var named name, you can use: dirname => "${name%/*}" basename => "${name##*/}" Sadly you can't use it with !$ since it's not a variable. The closest you can do is: $ ls foo/bar/baz ls: foo/bar/baz: No such file or directory $ last=!$; echo "${last##*/}" baz $ echo "${last%/*}" foo/bar
- falcolas 9y ago$ echo foo bar foo bar $ echo !$ echo bar bar The bang syntax is for history expansion, so it won't work on directories directly. But you could hack that with something like: $ls /root/my-dir [...] $echo !:t echo my-dir my-dir