Re: [opensuse] bash pipe
- From: Randall R Schulz <rschulz@xxxxxxxxx>
- Date: Tue, 30 Sep 2008 06:59:37 -0700
On Tuesday 30 September 2008 00:19, Brian K. White wrote:
----- Original Message -----
From: "David Bolt" <bcrafhfr@xxxxxxxxxx>
...
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##*/}"
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@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx
- Follow-Ups:
- Re: [opensuse] bash pipe
- From: David Bolt
- Re: [opensuse] bash pipe
- References:
- [opensuse] bash pipe
- From: drek
- Re: [opensuse] bash pipe
- From: David Bolt
- Re: [opensuse] bash pipe
- From: Brian K. White
- [opensuse] bash pipe
- Prev by Date: Re: [opensuse] Printing to PDF from Firefox - Something Broke
- Next by Date: [opensuse] DVR Software
- Previous by thread: Re: [opensuse] bash pipe
- Next by thread: Re: [opensuse] bash pipe
- Index(es):
Relevant Pages
|