Linux Shell Scripting TutorialIntroduction Tools required for shell scripting First shell script Interacting with user Operators Special characters in BASH scripting Variables in Linux BASH scripting Arrays Integer operations floating point operations String manipulation in shell scripting Parameter substitution Command Substitution Conditional statements Looping statements Passing parameters exit status of the script Functions Sourcing files
passing arguments in linux shell scriptingWe can pass the parameters (arguments) to shell script delimited by white spaces. You can access the current script name and arguments using $0, $1,$2….and so on.
- $0 = Script name (also called as base name of file)
- $1 = First argument to the script
- $2 = Second argument to the script and so on..
We can use below special variables to access the parameters.
if [ $# < 2 ] then echo “Count of parameters is less than 2” exit -1 fi
- [email protected] – All of the arguments.
- $* – All of the arguments. This does not preserve the white space and quotes.
- $$ – This gives you the process id of current shell.
- $! – This gives you the process id of last background process.
Complex problems, Simple Solutions