|
| 1 | +if else statements |
| 2 | +#ife.sh |
| 3 | +#!/bin/sh |
| 4 | +a=10 |
| 5 | +b=20 |
| 6 | +if [ $a == $b ] |
| 7 | +then |
| 8 | + echo "a is equal to b" |
| 9 | +else |
| 10 | + echo "a is not equal to b" |
| 11 | +fi |
| 12 | + |
| 13 | +#ife1.sh |
| 14 | +#if [ $# -lt 3 ] |
| 15 | +if (( $# == 3 )) |
| 16 | +then |
| 17 | +#Number of arguments on the command line. |
| 18 | +echo '$#:' $# |
| 19 | +#Process number of the current process. |
| 20 | +echo '$$:' $$ |
| 21 | +#Display the 3rd argument on the command line, from left to right. |
| 22 | +echo '$3:' $3 |
| 23 | +#Display the 10th argument on the command line, from left to right. |
| 24 | +echo '${10}:' ${10} |
| 25 | +#Display the name of the current shell or program. |
| 26 | +echo '$0:' $0 |
| 27 | +#Display all the arguments on the command line using * symbol. |
| 28 | +echo '$*:' $* |
| 29 | +#Display all the arguments on the command line using @ symbol. |
| 30 | +echo '$@:' $@ |
| 31 | +date |
| 32 | +echo '$?:' $? |
| 33 | +else |
| 34 | +echo "Please Pass the 3 command line args along with script" |
| 35 | +fi |
| 36 | + |
| 37 | +#ife2.sh |
| 38 | +#!/bin/bash |
| 39 | +echo -n "Enter a number: " |
| 40 | +read VAR |
| 41 | +if [ $VAR -gt 10 ] |
| 42 | +then |
| 43 | + echo "The variable is greater than 10." |
| 44 | +fi |
| 45 | + |
| 46 | +#ife3.sh |
| 47 | +#!/bin/bash |
| 48 | +echo -n "Enter a number: " |
| 49 | +read VAR |
| 50 | +if [ $VAR -gt 10 ] |
| 51 | +then |
| 52 | + echo "The variable is greater than 10." |
| 53 | +else |
| 54 | + echo "The variable is equal or less than 10." |
| 55 | +fi |
| 56 | + |
| 57 | +#ife4.sh |
| 58 | +#!/bin/bash |
| 59 | +echo -n "Enter a number: " |
| 60 | +read VAR |
| 61 | +if [ $VAR -gt 10 ] |
| 62 | +then |
| 63 | + echo "The variable is greater than 10." |
| 64 | +elif [ $VAR -eq 10 ] |
| 65 | +then |
| 66 | + echo "The variable is equal to 10." |
| 67 | +else |
| 68 | + echo "The variable is less than 10." |
| 69 | +fi |
| 70 | + |
| 71 | + |
| 72 | +#ife5.sh |
| 73 | +#!/bin/bash |
| 74 | +echo -n "Enter the first number: " |
| 75 | +read VAR1 |
| 76 | +echo -n "Enter the second number: " |
| 77 | +read VAR2 |
| 78 | +echo -n "Enter the third number: " |
| 79 | +read VAR3 |
| 80 | +if [ $VAR1 -ge $VAR2 ] && [ $VAR1 -ge $VAR3 ] |
| 81 | +then |
| 82 | + echo "$VAR1 is the largest number." |
| 83 | +elif [ $VAR2 -ge $VAR1 ] && [ $VAR2 -ge $VAR3 ] |
| 84 | +then |
| 85 | + echo "$VAR2 is the largest number." |
| 86 | +else |
| 87 | + echo "$VAR3 is the largest number." |
| 88 | +fi |
0 commit comments