coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting current directory name


From: Pádraig Brady
Subject: Re: Getting current directory name
Date: Thu, 29 Sep 2016 14:29:21 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

On 29/09/16 13:59, Ковалев Кирилл wrote:
> Hello!
> 
> I'm writing for the first time in such list, so any advices are appreciated.
> 
> Let's say, we got a path: "/home/user/dir". *I'd like to obtain just a
> string "dir".*
> 
> I tried to execute "basename" utility with no success:
> 
> $ basename

Does basename output the logical or physical basename in this case?
(See below)...

> $ pwd | basename

Yes basename operates only on arguments rather than items from stdin.
Processing multiple arguments is supported with `generate_paths | xargs 
basename -a`
If we added operation as a filter then newer scripts using that would
break compatibility with older utilities, for no functional gain.
Also processing multiple paths is edge case functionality.

> Then I open manual / help message and realize that correct way to use it is:
> 
> $ basename $(pwd)
> 
> Which seems for me to be non-intuitive, compared with these I tried to use.

The vast majority of use is to specify a single path,
so a single argument works best for that.

Given the variables involved the current syntax seems best, which is:

basename "$(pwd -P)"
or
basename "$(pwd -L)"

p.s. use `env pwd` to get the system installed binary
rather than the shell builtin equivalent.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]