Re: :t and getting senile.
- From: Stephane CHAZELAS <this.address@xxxxxxxxxx>
- Date: Mon, 25 Sep 2006 21:23:23 +0100
2006-09-25, 12:22(-07), george.e.sullivan@xxxxxxxx:
Ok, I know I am getting old. I can't remember where I saw this, but[...]
how do you strip off the end of string such as a command line string so
that you just get the last part after the slash bar?
Ex: /here/there/everywhere/hello.
There was something I saw somewhere with a :t that would just give me
the hello part.
That's a csh feature also found in tcsh and zsh. That comes from
history substitution. bash implemented csh history substitution
but didn't go as far as that.
$file:r (rest (without extension)) $file:h (head), $file:t
(tail).
With bash it's only available via the csh-like history
substitution:
It can also be found in vim. :cd %:h changes vim current
directory the the directory part of the currently edited file.
bash-3.1$ echo a/b.c
a/b.c
bash-3.1$ echo !$:t
echo b.c
b.c
bash copied the bogus ${array:index:length} from ksh that makes
it not-really-compatible with ${var:modifier}. zsh used the more
sensible ${var[start,end]}, so was able to borrow the
$var:modifier from csh.
$var:h in zsh gives the dirname even for the cases where
${var%/*} fails such as when var=foo (not with csh or tcsh).
Same for $var:t vs ${var##*/} when var=/foo/.
--
Stéphane
.
- Follow-Ups:
- Re: :t and getting senile.
- From: Stephane Chazelas
- Re: :t and getting senile.
- References:
- :t and getting senile.
- From: george . e . sullivan
- :t and getting senile.
- Prev by Date: Re: :t and getting senile.
- Next by Date: capture output of an ldapmodify command
- Previous by thread: Re: :t and getting senile.
- Next by thread: Re: :t and getting senile.
- Index(es):
Relevant Pages
|