Last active
March 28, 2019 10:53
-
-
Save blackzphoenix/a8a6d8fa7a17d6b468adb816bac54648 to your computer and use it in GitHub Desktop.
Problem based on decision
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
| #first | |
| #!/bin/bash -x | |
| echo "Hello ${LOGNAME}" | |
| echo "Today is $(date)" | |
| echo "Users currently on the machine, and their processes:" | |
| #Second | |
| #!/bin/bash | |
| #This is an Example of Single line Comment! | |
| echo "Welcome !!" | |
| #!/bin/bash | |
| echo "Welcome!!" | |
| <<COMMENT | |
| Multiple line Comment : Usage | |
| Commenting two or more lines of a script | |
| Can be used to explain the written code | |
| COMMENT | |
| echo "End!!" | |
| #Third | |
| #!/bin/bash | |
| read -p "Enter a Password : " pass | |
| if test "$pass" == "gnu" | |
| then | |
| echo "Password verified." | |
| fi | |
| #Update | |
| ##!/bin/bash | |
| read -p "Enter a password" pass | |
| if test "$pass" = ""gnu | |
| then | |
| echo "Password verified." | |
| else | |
| echo "Access denied." | |
| fi | |
| #Fourth | |
| #!/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 | |
| #Update | |
| #!/bin/bash | |
| read -p "Enter a number : " num | |
| if [ $num -gt 0 ]; | |
| then | |
| echo "$num is a positive." | |
| elif [ $num -lt 0 ] | |
| then | |
| echo "$num is a negative." | |
| elif [ $num -eq 0 ] | |
| then | |
| echo "$num is zero number." | |
| else | |
| echo "OMG! Wasn't $num a number." | |
| fi | |
| #Fifth | |
| #!/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 | |
| echo "User '$username' not found in $FILE file." | |
| fi | |
| #Sisth | |
| #!/bin/bash | |
| [ ! -d /shell ] && mkdir /shell | |
| [ ! -f /prog1.sh ] && touch prog1.sh | |
| test ! -f /etc/resolv.conf && echo "File /etc/resolv.conf not found." || echo "File /etc/resolv.conf found." | |
| #Update | |
| #!/bin/bash | |
| [ ! -d shell ] && (echo "Directory created", mkdir shell) || ( echo "Directory not created) | |
| [ ! -f prog1.sh ] && touch prog1.sh | |
| #Seven | |
| #!/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 | |
| echo "Wrong Password !!" | |
| else | |
| echo "Authentication of password Success!" | |
| fi | |
| #Eight | |
| #!/bin/bash | |
| IFS="- " | |
| echo "The script name : $0" | |
| echo "The first argument to the script : $1" | |
| echo "The second argument to the script : $2" | |
| echo "The third argument to the script : $3" | |
| echo "The fourth argument to the script : $4" | |
| echo "The number of arguments passed to the script : $#" | |
| echo "* Display all free Softwares names usinng (\$@ version) : $@" | |
| echo | |
| echo "* Display all Free Softwares names using (\$* version) : $*" | |
| #Nine | |
| #!/bin/bash | |
| NOW=$(date +"%a") | |
| case $NOW in | |
| Mon) | |
| echo "Full backup", $NOW;; | |
| Tue|Wed|Thu|Fri) | |
| echo "Partial backup", $NOW;; | |
| Sat|Sun) | |
| echo "No backup", $NOW;; | |
| *) ;; | |
| esac | |
| #Tenth | |
| file 1: prog.sh | |
| #!/bin/bash | |
| var=$1 | |
| case $var in | |
| maths) | |
| echo "In Engineering we have MATHS in 1st to 4th Sem..." | |
| ;; | |
| phy) | |
| echo "Luckily or Sadly we have we have PHYSICS only for 1st or 2nd Sem..." | |
| ;; | |
| ece|cse|ise|ae|ipe|ce|eee) | |
| echo "Now its time to ask Seniors..." | |
| ;; | |
| *) | |
| echo "PSECE" | |
| echo "Welcome to $var Department !!!" | |
| echo "Have a nice time !!" | |
| echo " $var : Departmental Issues!! talk to HOD" ;; | |
| esac | |
| file2 : execute.sh | |
| chmod +x prog.sh | |
| ./prog.sh maths | |
| ./prog.sh phy | |
| ./prog.sh ec |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment