Difference between revisions of "Trillex bash 1"
From Teknologisk videncenter
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 | ||
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." |
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"