Re: :t and getting senile.



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
.



Relevant Pages

  • Re: Not working in bash or csh
    ... You have to look for info about the echo command, ... I don't know about csh, but for bash try: ...
    (comp.unix.shell)
  • Re: make buildworld does nothing
    ... If you have bash running out of .cshrc, then that is probably your problem, ... are csh scripts will not function because bash will start... ... I added an echo to my .cshrc file: ...
    (freebsd-stable)
  • Re: print command
    ... >> the last echo is to get the newline to print. ... Basically this is the bash for loop. ... My perl example was pretty bad: ... This prints the string "*" 80 times and sticks "\n" at the end. ...
    (Debian-User)
  • Re: csh/bash : path/PATH
    ... > I posted some questions about csh path and thanks for the replies I ... > bash here. ... > $path is also a shell pre-defined variable. ... echo "$PATH" ...
    (comp.unix.shell)
  • Re: $ not allowed with $?
    ... How to get csh to output the right string ... echo if '' echo Variable Y does not exist ...
    (comp.unix.shell)