On Tuesday 30 September 2008 00:19, Brian K. White wrote:
----- Original Message ----- From: "David Bolt" <bcrafhfr@davjam.org>
...
This should do:
WHICHEVER_VARIABLE_NAME_YOU_WANT=${PWD##*/}
Ahh finally! Phew I was wondering if _anyone_ was going to say anything other than the unnecessary process fork of running basename.
I'd composed a message with this (and the dirname counterpart, ${PWD%/*}), but by the time I added all the caveats for the special cases in which this differs from basename and dirname when you're in the root directory or, for the dirname substitute, any directory whose immediate parent is the root, I decided it wasn't worth it. Here's what I wrote but didn't send at the time: -==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==- On Monday 29 September 2008 06:11, drek wrote:
Hello,
In a script I want to know in which directory I am, but I don't want to know the whole path. ...
Anyone with an explanation?
You've gotten that already, but I'll give you the most concise and lowest overhead way to do what you want: % echo "$PWD" /home/rschulz/Mail % echo "${PWD##*/}" Mail The reverse is possible, too: % echo "${PWD%/*}" /home/rschulz However, the second one doesn't work well if you're in "/" or a directory whose immediate parent is "/", in which case you get an empty string. The first gives you an empty string if you're in "/", which may or may not be acceptable for you. It is different than what basename and dirname yield, certainly. -==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==-
-- Brian K. White
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org