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.
dirname is a standard computer program on Unix and Unix-like operating systems. When dirname is given a pathname, it will delete any suffix beginning with the last slash ( '/' ) character and return the result. dirname is described in the Single UNIX Specification and is primarily used in shell scripts. dirname.
dirname $0 takes a filename (in this case, $0 or the path where the shell found that file), and echo es the directory that it is stored in.
The functions dirname() and basename() break a null-terminated pathname string into directory and filename components. In the usual case, dirname() returns the string up to, but not including, the final '/', and basename() returns the component following the final '/'.
$* Stores all the arguments that were entered on the command line ($1 $2 ...). "$@" Stores all the arguments that were entered on the command line, individually quoted ("$1" "$2" ...). So basically, $# is a number of arguments given when your script was executed. $* is a string containing all arguments.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With