Skip to content

Instantly share code, notes, and snippets.

View blackzphoenix's full-sized avatar
🎯
Focusing

Black ZPhoenix blackzphoenix

🎯
Focusing
View GitHub Profile
@blackzphoenix
blackzphoenix / string_shell.sh
Last active March 27, 2019 23:44
string comparison
#!/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
#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
#!/bin/bash
[ ! -d shell ] && mkdir shell
[ ! -f prog1.sh ] && touch prog1.sh
@blackzphoenix
blackzphoenix / LNot_shell.sh
Last active March 27, 2019 23:40
logical not
! expression [ ! expression ] if test ! condition if [ ! condition ]
then then
command1 command1
... ...
commandN commandN
fi fi
#!/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
@blackzphoenix
blackzphoenix / multi_if_else_shell.sh
Last active March 27, 2019 18:32
multi level if_ else
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
@blackzphoenix
blackzphoenix / nested.sh
Last active March 27, 2019 18:22
nested loop
if condition
then
if condition
then
command1
.....
..
commandN
else
command1
@blackzphoenix
blackzphoenix / number_shell.sh
Last active March 27, 2019 23:36
positive or negative
#!/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
@blackzphoenix
blackzphoenix / if_else_shell.sh
Created March 27, 2019 17:54
if else fi condition
if condition if test var -eq val
then then
command1 command1
command2 command2
... ...
commandN commandN
else else
command1 command1
command2 command2
... ...
@blackzphoenix
blackzphoenix / pass_shell.sh
Created March 27, 2019 17:43
conditional password using if
#!/bin/bash
read -p "Enter a Password : " pass
if test "$pass" == "gnu"
then
echo "Password verified."
fi