Saturday, September 14, 2019

Unix Shell Scripting Part - 2

if statement:

[oracle@ODIGettingStarted practice]$ vi ifstatement.sh
[oracle@ODIGettingStarted practice]$ cat ifstatement.sh
#If statement example
echo -n Enter first number:
read a
echo -n Enter second number:
read b
if [ $a -eq $b ]
then
   echo $a "is equal to" $b
else
   echo $a is not equal to $b
fi
[oracle@ODIGettingStarted practice]$ sh ifstatement.sh
Enter first number:5
Enter second number:5
5 is equal to 5
[oracle@ODIGettingStarted practice]$ sh ifstatement.sh
Enter first number:5
Enter second number:6
5 is not equal to 6
[oracle@ODIGettingStarted practice]$

ifelif statement:

[oracle@ODIGettingStarted practice]$ vi elifstatemnt.sh
[oracle@ODIGettingStarted practice]$ cat elifstatemnt.sh
#Purpose: Compare given two numbers
#Version: 1.0
#Created Date: Sat Sep 14 07:42:10 PM IST 2019
#Modified Date:
#Author: Rajasekhar Royal
# START #
echo -n Enter first number:
read a
echo -n Enter second number:
read b
if [ $a -eq $b ]; then
   echo $a is equal to $b
elif [ $a -gt $b ]; then
   echo $a is greater than $b
else
   echo $a is less than $b
fi
# END #
[oracle@ODIGettingStarted practice]$
[oracle@ODIGettingStarted practice]$ sh elifstatemnt.sh
Enter first number:35
Enter second number:20
35 is greater than 20
[oracle@ODIGettingStarted practice]$

while

[oracle@ODIGettingStarted practice]$ vi whiletest.sh
[oracle@ODIGettingStarted practice]$ cat whiletest.sh
myvar=1
while [ $myvar -le 10 ]
do
echo $myvar
        myvar=$(( $myvar + 1 ))
        sleep 0.5
done
[oracle@ODIGettingStarted practice]$ sh whiletest.sh
1
2
3
4
5
6
7
8
9
10
[oracle@ODIGettingStarted practice]$
[oracle@ODIGettingStarted practice]$ vi whiletest.sh
[oracle@ODIGettingStarted practice]$ cat whiletest.sh
myvar=1
while [ $myvar -le 5 ]
do
echo $myvar
        #myvar=$(( $myvar + 1 ))
        myvar=` expr $myvar + 1 `
        sleep 0.5
done
[oracle@ODIGettingStarted practice]$ sh whiletest.sh
1
2
3
4
5
[oracle@ODIGettingStarted practice]$

for loop

[oracle@ODIGettingStarted practice]$ vi forloop.sh
[oracle@ODIGettingStarted practice]$ cat forloop.sh
echo way-1
for i in 0 1 2 3 4 5
do
  echo $i
done
echo way-2
for i in {0..5}
do
  echo $i
done
echo way-3
max=5
for((i=0;i<=$max;i++));
do
  echo $i
done
[oracle@ODIGettingStarted practice]$ sh forloop.sh
way-1
0
1
2
3
4
5
way-2
0
1
2
3
4
5
way-3
0
1
2
3
4
5

[oracle@ODIGettingStarted practice]$

No comments:

Post a Comment

Delete Row Button to all records of Interactive Report in Oracle Apex

 1. add 'Delete' Del column to Report Query 2. Set the Following Properties for the DEL Column Type: Link Heading: Delete Targ...