1st line -->#!/bin/bash
shebang is the location interpreter, commands written inside shell script is interpreted and executed by this shebang
bash shell == shell
sh <script> bash <script> ./ --> this should have execute permission X --> running the command/script passing the arguments/paraments command "sh variables.sh person1 person2"
- repeated words
- if you want to change, you have to change it every where
- while changing accidently you may change actual code 4 symbol -s denotes for hiding the details like username & password ex:echo "please enter username read -s USERNAME
array---> List of values
If you defined as array, it can hold list of values.....
Variable can be decleared as
-
"All variables: $@"
-
"Number of Variables passwd: $#"
-
"script name $0"
-
"current working directory: $PWD"
-
"Home directory of current user: $HOME"
-
"which user is running the script: $USER"
-
"Host name: $HOSTNAME"
-
"process ID of current shell script: $$"
-
sleep 5 & [& denotes seconds]
-
"process ID of last background command: $!"
- when you want to take decision
- ex:I want to check whether a number is greater than 20 or not
- first get the number
- check if it is greater than 10 or not
- if greater print greater
- if less print lower
#!=false
#-gt=greater than, -lt=lesser than, -eq=eqaul to, -ge=greater than or equal to, -le=lesser than or equal to syntax
NUMBER=5 if(!NUMBER>10){ print "print given number is greater than 10" } else{ print "print given number is less than 10" }
shell script will not stop even it faces the error, it is user responsibility to check the previous command is success/not
what is exit status?
$? --> to check the exit status of previous command 0 --> success other than 0 --> failure