3 ms·
Can someone explain :h as the article's description was not clear at all to me what was going on there.
by indigodaddy 9y ago
Can someone explain :h as the article's description was not clear at all to me what was going on there.
- mmjaa 9y agoYeah, 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
- jwilk 9y agoWild guess: perhaps OP confused bash syntax with vim syntax, where :h removes the last component? http://vimdoc.sourceforge.net/htmldoc/cmdline.html#filename-modifiers http://vimdoc.sourceforge.net/htmldoc/cmdline.html#filename-...
- falcolas 9y agoIt's !:h - not just a plain :h $ echo foo /bar foo /bar $ !:h echo foo foo It's under `man bash` in the History Expansion section.
- pimlottc 9y agoThat's not quite what the author was talking about; your example does the same thing as !:0- This is what the author meant: $ echo foo/bar foo/bar $ !:h echo foo foo
- emmelaich 9y agoYes, the article is flat out wrong there. Probably a typo or pasto though. Instead of ls /long/path/to/some/file/or/other.txt:h it should be ls !:$:h which would produce other.txt