Bash script argument default value and takes optional input arguments

In this tutorial, I have written bash script Bash script argument default value and takes optional input arguments.
  • Using $# argument to input parameter  in bash script.
To run bash script with argument default
./def_argument_default.sh
The display argument default as below:

Bash script argument default value and takes optional input arguments

Running bash script with argument
 ./def_argument_default.sh argument1 argument2 argument3
The display bash script with argument as below:

My bash script argument default value and takes optional input arguments as below:
#!/bin/bash
###############
# bash script argument default value
# running argument default: 
#    ./def_argument_default.sh 
# Running optional input argument:
#    ./def_argument_default.sh argument1 argument2 argument3
#
###############
argument1=HUU
argument2=PHAN
argument3=www.huuphan.com
RED='\033[0;31m'
NC='\033[0m' # No Color
if [ $# -eq 3 ];then
    argument1=$1
    argument2=$2
    argument3=$3
fi
echo -e "First Name: $RED \t$argument1 $NC"
echo -e "Last Name:  $RED \t$argument2 $NC"
echo -e "My Site: $RED \t$argument3 $NC"

Comments

Popular posts from this blog

zimbra some services are not running [Solve problem]

Bash script list all IP addresses connected to Server

How to install and configure zimbra multi server