Reputation: 2291
Can any body tell me what this command means?
selfDir=$(cd "$(dirname "$0")"; pwd) ?
I know
$0
= running script namepwd
= current working dircd
= to change dirWhat I need is what is dirname? and what ? means at end to make this line completely understandable.
Upvotes: 6
Views: 19332
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
Upvotes: 5