Elvin
Elvin

Reputation: 2291

Linux Shell script what dirname and ? means?

Can any body tell me what this command means?

selfDir=$(cd "$(dirname "$0")"; pwd) ?

I know

What I need is what is dirname? and what ? means at end to make this line completely understandable.

Upvotes: 6

Views: 19332

Answers (1)

Vinayak Pahalwan
Vinayak Pahalwan

Reputation: 3005

The dirname command removes the trailing / component from the NAME and prints the remaining portion. If the NAME does not contain / component then it prints '.' (means current directory)

Dirname Command Example:

Remove the file name from absolute path.

Let say my directory path is /usr/local/bin/add.sh. Now i want to remove /add.sh and display only /usr/local/bin, then we can use the dirname command.

dirname /usr/local/bin/add.sh
/usr/local/bin

NAME

dirname - strip non-directory suffix from file name

SYNOPSIS

dirname NAME 
dirname OPTION 

DESCRIPTION

Print NAME with its trailing /component removed; if NAME contains no /’s, output ‘.’ (meaning the current directory).

Edit: Also, Some characters have special functions in linux commands ? <-- Matches one character

Source

Upvotes: 5

Related Questions