How to create a shell script using the conditional statement on CentOS and RHEL 6/7 step by step guide
In this
article we will learn how to create a shell script using the conditional statement
and execute it on CentOS and RHEL linux
system and we are going to create a script with bash if statement to demonstrate example.
Shell
script is very powerful language for a system admin to execute the daily basic
staff.
In this
article we use if else statement to understand the example.
Following
bash operators are useful to write a conditional shell script program.
bash operator in shell script for linux unix system| techrideradmin |
How to create a shell script using if else statement on linux system
======================================================================
Now we are
going to write one small shell script program to understand how conditional
statement works in the shell script program on the linux system .
First we create one empty file named condition .sh using the below command.
#touch condition.sh
After creating empty file we enter
the below line to create bash if statement in the file.
#!/bin/bash
echo How old are you?
read age
if [ “$age” –gt 25 ] then
echo you can drive
else
echo you can not drive
fi
note: we shoule use #!/bin/bash to
identify this script only run in bash shell not the other shell .
How to execute the shell script program
======================================================================
To execute this
program we need to execute the below command.
[root@localhost ~]# sh condition.sh
After execute the
above command we can find the below output..
Output:
How old are you?
18
you can not drive
How to create a shell script using the conditional statement on CentOS and RHEL 6/7 step by step guide |
That’s all. If this
article is helpful to know about bash if statement please share it!!!!
Please Donate To Bitcoin Address: [[address]]
Donation of [[value]] BTC Received. Thank You.
[[error]]
0 comments:
Post a Comment