Conditionals
Shell scripts can accept positional arguments. They also have some useful built-in arguments.
Write The Shell Script
#!/bin/sh
echo 'This is the first argument:'
echo $1
echo 'This is the second argument:'
echo $2
echo 'This is the third argument:'
echo $3
echo '-----------'
echo 'This is the number of arguments:'
echo $#
echo '-----------'
echo 'This is all the arguments':
echo [email protected]
echo '-----------'
echo 'This is the process ID':
echo $$
echo '-----------'
echo 'This is the script filename':
echo $0
echo '-----------'
echo 'This is the exit code':
echo $?
Run The Shell Script
sh arguments.sh banana apple grape
This is the first argument:
banana
This is the second argument:
apple
This is the third argument:
grape
-----------
This is the number of arguments:
3
-----------
This is all the arguments:
banana apple grape
-----------
This is the process ID:
92787
-----------
This is the script filename:
test.sh
-----------
This is the exit code:
0