Notes on Shell Scripts

While reading some of the scripts written by my colleagus, I found some usages to be quite tricky. Thus I keep a note of the usage here.

1.filename and extension parts

1
2
3
4
5
6
7
8
9
10
echo `basename $PWD` # Basename of current working directory.
echo "${PWD##*/}" # Basename of current working directory.
echo
echo `basename $0` # Name of script.
echo $0 # Name of script.
echo "${0##*/}" # Name of script.
echo
filename=test.data
echo "${filename##*.}" # data
# Extension of filename.

2.