Hi,
Could you please help me to know the difference between
$0 and basename in unix how they useful in shell scripting.
Thanks in advance
Hi,
Could you please help me to know the difference between
$0 and basename in unix how they useful in shell scripting.
Thanks in advance
$0 will contain the name of your shell script.
basename is used to strip directory and suffix from filenames
See below for easy understanding:
$$>>cat testers.sh
#!/bin/sh
path="/a/b/c/d/e/f/g.txt"
bn=`basename $path`
echo "basename is $bn and script name is $0"
output is:
$$>>testers.sh
basename is g.txt and script name is testers.sh
Thanks...
Also, normally $0 will contain the name of the script the way it was called, you can strip off the path using basename "$0"
to get the name of the script itself.