Shell Scripting
By Karthik V
$#, $@ & $?: Bash Built-in variables
file:test.sh
#! /bin/sh
echo '$#' $#
echo '$@' $@
echo '$?' $?
*If you run the above script as*
> ./test.sh 1 2 3
You get output:
$# 3
$@ 1 2 3
$? 0
*You passed 3 parameters to your script.*
$# = number of arguments. Answer is 3
$@ = what parameters were passed. Answer is 1 2 3
$? = was last command successful. Answer is 0 which means 'yes'
if else
##!/bin/bash
read -p "Enter a password" pass
if test "$pass" = "jerry"
then
echo "Password verified."
else
echo "Access denied."
fi
if Condition
#!/bin/bash
# Basic if statement
if [ $1 -gt 100 ]
then
echo Hey that\'s a large number.
fi
References:
http://unix.ittoolbox.com/groups/technical-functional/unixadmin-l/difference-betwee
n-0-and-in-unix-shell-scripts-1789925