Difference between revisions of "Nohvok Bash Scripting"
From Teknologisk videncenter
(New page: == Bash Scripting == === Lidt ekspempler på Scripts === ==== Greetings ==== <source lang="bash"> #!/bin/bash #Uncomment HOUR=`date +%H` when using for real #HOUR=`date +%H` # #HOUR=$1 onl...) |
m (→) |
||
(One intermediate revision by one other user not shown) | |||
Line 77: | Line 77: | ||
Skrevet af Morten Fallesen | Skrevet af Morten Fallesen | ||
− | [[Category:Linux]] [[Category:H2] [Category:Bash | + | [[Category:Linux]] [[Category:H2]] [[Category:Bash]] |
Latest revision as of 10:16, 15 May 2009
Contents
Bash Scripting
Lidt ekspempler på Scripts
Greetings
#!/bin/bash
#Uncomment HOUR=`date +%H` when using for real
#HOUR=`date +%H`
#
#HOUR=$1 only for testing purposes.....
HOUR=$1
if test $HOUR -le 7
then
echo "You are early go home"
else if test $HOUR -le 8
then
echo "You are early"
else if test $HOUR -lt 12
then
echo "Good morning, Vietnam"
else if test $HOUR -lt 16
then
echo "Good evening"
fi
fi
fi
fi
while
count example
#!/bin/bash
COU=1
while test $COU -lt 10000
do
echo -en "COU = $COU\r"
COU=`expr $COU + 1`
done
case
secret password example
#!/bin/bash
# Read the username from the terminal
echo -en "Enter username: "
read USERNAME
# Read the password from the terminal not echoing the characters
echo -en "Enter password: "
stty -echo
read PASSWORD
stty echo
# Find the username in the case and check password
case $USERNAME in
john|John) if test $PASSWORD = "banana"
then
echo "Access granted"
else
echo "Access denied...."
exit
fi
;;
eve|Eve) if test $PASSWORD = "apple"
then
echo "Access granted"
else
echo "Access denied...."
exit
fi
;;
*) echo "Access denied...."
exit
;;
esac
echo "The secret information is 198273"
Skrevet af Morten Fallesen