This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| read -s -p "Enter your password : " pass | |
| echo | |
| #checks whether the string is non zero | |
| if test -z $pass | |
| then | |
| echo "No password was entered!!! Cannot verify an empty password!!!" | |
| exit 1 | |
| elif test "$pass" != "gnu" | |
| then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Numerical Comparison | |
| eq INTEGER1 -eq INTEGER2 INTEGER1 is equal to INTEGER2 | |
| ge INTEGER1 -ge INTEGER2 INTEGER1 is greater than or equal to INTEGER2 | |
| gt INTEGER1 -gt INTEGER2 INTEGER1 is greater than INTEGER2 | |
| le INTEGER1 -le INTEGER2 INTEGER1 is less than or equal to INTEGER2 | |
| lt INTEGER1 -lt INTEGER2 INTEGER1 is less than INTEGER2 | |
| ne INTEGER1 -ne INTEGER2 INTEGER1 is not equal to INTEGER2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| [ ! -d shell ] && mkdir shell | |
| [ ! -f prog1.sh ] && touch prog1.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ! expression [ ! expression ] if test ! condition if [ ! condition ] | |
| then then | |
| command1 command1 | |
| ... ... | |
| commandN commandN | |
| fi fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| FILE=/etc/passwd | |
| read -p "Enter a user name : " username | |
| #locate the username in the file passwd | |
| if grep "^$username:" /etc/passwd >/dev/null | |
| then | |
| echo "User '$username' found in $FILE file." | |
| else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if condition | |
| then | |
| condition is true | |
| execute all commands up to elif statement | |
| elif condition1 | |
| then | |
| condition1 is true | |
| execute all commands up to elif statement | |
| elif condition2 | |
| then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if condition | |
| then | |
| if condition | |
| then | |
| command1 | |
| ..... | |
| .. | |
| commandN | |
| else | |
| command1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| read -p "Enter a number : " num | |
| if test $num -ge 0 | |
| then | |
| echo "$num is Positive number." | |
| else | |
| echo "$num number is Negative number." | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if condition if test var -eq val | |
| then then | |
| command1 command1 | |
| command2 command2 | |
| ... ... | |
| commandN commandN | |
| else else | |
| command1 command1 | |
| command2 command2 | |
| ... ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| read -p "Enter a Password : " pass | |
| if test "$pass" == "gnu" | |
| then | |
| echo "Password verified." | |
| fi |