Difference between revisions of "Trillex bash 1"
From Teknologisk videncenter
(New page: Category:LinuxCategory:H2Category:bash = Bash Scripts and Commands = == Bash Commands == == Bash Scripts == === Program for greeting users. Doesn't work === #!/bin/bash clear ...) |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
== Bash Commands == | == Bash Commands == | ||
== Bash Scripts == | == Bash Scripts == | ||
− | === Program for greeting users | + | === Program for greeting users (Advanced - can be made better) === |
− | #!/bin/bash | + | #!/bin/bash |
− | clear | + | clear |
− | echo -e "Welcome to my new bash-script" | + | echo -e "Welcome to my new bash-script" |
− | echo -e "=============================" | + | echo -e "=============================" |
− | echo -e "\n\n" # \n is the new-line command. So there will be two empty lines here | + | echo -e "\n\n" # \n is the new-line command. So there will be two empty lines here |
− | echo -e "Rune Nordblom\nPRC-Data, Viborg\nDenmark" | + | echo -e "Rune Nordblom\nPRC-Data, Viborg\nDenmark" |
− | echo -e "The time is `date +%H:%M`." | + | echo -e "The time is `date +%H:%M`." |
− | HOUR=`date +%H` | + | HOUR=`date +%H` |
− | MINUTE=`date +%M` | + | MINUTE=`date +%M` |
− | if test $HOUR -le 7 | + | if test $HOUR -le 7 |
then | then | ||
echo -e "Please go to sleep." | echo -e "Please go to sleep." | ||
Line 20: | Line 20: | ||
then | then | ||
echo -e "You are early." | echo -e "You are early." | ||
− | else if test | + | else if test $HOUR -lt 11 -a $MINUTE -lt 59 |
then | then | ||
echo -e "Good Morning." | echo -e "Good Morning." | ||
− | else if test | + | else if test $HOUR -lt 11 -a $MINUTE -lt 59 |
then | then | ||
echo -e "Good afternoon." | echo -e "Good afternoon." | ||
Line 33: | Line 33: | ||
fi | fi | ||
fi | fi | ||
− | fi | + | fi |
− | ==== Same | + | ==== Same As Above But Less Advanced and Working ==== |
− | #!/bin/bash | + | #!/bin/bash |
− | clear | + | clear |
− | echo -e "Welcome to my new bash-script" | + | echo -e "Welcome to my new bash-script" |
− | echo -e "=============================" | + | echo -e "=============================" |
− | echo -e "\n\n" # \n is the new-line command. So there will be two empty lines here | + | echo -e "\n\n" # \n is the new-line command. So there will be two empty lines here |
− | echo -e "Rune Nordblom\nPRC-Data, Viborg\nDenmark" | + | echo -e "Rune Nordblom\nPRC-Data, Viborg\nDenmark" |
− | echo -e "The time is `date +%H:%M`." | + | echo -e "The time is `date +%H:%M`." |
− | HOUR=`date +%H` | + | HOUR=`date +%H` |
− | MINUTE=`date +%M` | + | MINUTE=`date +%M` |
− | if test $HOUR -lt 7 | + | if test $HOUR -lt 7 |
then echo -e "Please go to sleep." | then echo -e "Please go to sleep." | ||
elif test $HOUR -lt 8 | elif test $HOUR -lt 8 | ||
Line 56: | Line 56: | ||
elif test $HOUR -gt 16 | elif test $HOUR -gt 16 | ||
then echo -e "Please go home." | then echo -e "Please go home." | ||
− | fi | + | fi |
+ | |||
+ | === Case Script === | ||
+ | |||
+ | #!/bin/bash | ||
+ | # Read the username from the terminal | ||
+ | clear | ||
+ | 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 | ||
+ | clear | ||
+ | # 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 123123123" |
Latest revision as of 11:21, 12 February 2009
Contents
Bash Scripts and Commands
Bash Commands
Bash Scripts
Program for greeting users (Advanced - can be made better)
#!/bin/bash clear echo -e "Welcome to my new bash-script" echo -e "=============================" echo -e "\n\n" # \n is the new-line command. So there will be two empty lines here echo -e "Rune Nordblom\nPRC-Data, Viborg\nDenmark" echo -e "The time is `date +%H:%M`." HOUR=`date +%H` MINUTE=`date +%M` if test $HOUR -le 7 then echo -e "Please go to sleep." else if test $HOUR -le 8 then echo -e "You are early." else if test $HOUR -lt 11 -a $MINUTE -lt 59 then echo -e "Good Morning." else if test $HOUR -lt 11 -a $MINUTE -lt 59 then echo -e "Good afternoon." else if test $HOUR -gt 16 then echo -e "Please go home." fi fi fi fi fi
Same As Above But Less Advanced and Working
#!/bin/bash clear echo -e "Welcome to my new bash-script" echo -e "=============================" echo -e "\n\n" # \n is the new-line command. So there will be two empty lines here echo -e "Rune Nordblom\nPRC-Data, Viborg\nDenmark" echo -e "The time is `date +%H:%M`." HOUR=`date +%H` MINUTE=`date +%M` if test $HOUR -lt 7 then echo -e "Please go to sleep." elif test $HOUR -lt 8 then echo -e "You are early." elif test $HOUR -lt 11 then echo -e "Good Morning." elif test $HOUR -lt 15 then echo -e "Good afternoon." elif test $HOUR -gt 16 then echo -e "Please go home." fi
Case Script
#!/bin/bash # Read the username from the terminal clear 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 clear # 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 123123123"