Huu Phan | Blog Linux operating system | Linux operating system -Blog Huu Phan | www.huuphan.com
huuphan.com. Powered by Blogger.

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 output  argument default:

Bash script argument default value and takes optional input arguments
To run  optional input argument
 ./def_argument_default.sh argument1 argument2 argument3
The output optional input argument:

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"

post new :

Huu Phan | Blog Linux operating system | Huu Phan ~ Zimbra Mail Server,linux,bash script,centos,linux command | www.huuphan.com