$PATH $SHELL
&& ans list --- A string of commands where the next command is only executed if
the previous command exited with astatus of zero
|| ans list --- A string of commands where the next command is only executed if
the previous command exited with a non-zero status
Zero Exit Status:
Implies the script or program ran to
completion and everything is fine.
Non-Zero Exit Status:
Results can vary based on the script
or program that generated the exit status.
the $? variable is used to determine the exit status of the last command executed.
> file_name
>> file_name # append data to file
< file_name
2> file_name
2>> file_name
1> file_name
1>> file_name
echo "abc 123">file
exec 5<> file
read -n3 var <&5
echo $var
exec 5>&-
VARIABLE_NAME = VARIABLE_VALUE
echo $VARIABLE_NAME
function name {
code
exit status
}
function hello {
echo "Hello World"
}
hello
quit
Number=(1 2 3 4 5)
Number+= 9 #append 9 to the array
echo ${Number[0]}
echo ${Number[@]}
echo ${#Number[*]} #length of array
rpm -qf /usr/bin/bash
rpm -qf `wich yum`
rpm -qf $(which yum)
TIME = $(date +%H:%M:%S)
bash <(curl -s https://raw.githubusercontent.com/user/repo/master/script.sh)
for i in $(ls); do echo $i done
for i in {1..10}; do touch file$i done
while [ $i -le 10 ]; do
echo
until [ $i -gt 10 ]; do
echo
Programs in Linux are managed pratilly by signals from the kernel.
SIGINT: Interrupt SIGKILL: Kill SIGTERM: Terminate SIGUSR1: User defined 1
if ()
then
command
else
command
fi
A heredoc is a special type of redirection that allows you to pass multiple lines of input to a command.
cat << DELIMITER This is a heredoc. It is useful for passing multiple lines of input to a command. DELIMITER
Is a pared-down version of heredoc.
command <<< "$WORD"
set -x set -u set -e
- break: Breaks out of a loop.
- continue: Continues to the next iteration of a loop.
- readonly: Makes a variable readonly cannot be modified. If we put -x intialy on /bin/bash we can view how process code
Regular expressions are a way to match or search patterns.
grep -E "^[0-9]+$"
grep -E '<is>|am' # <> is used for matching the word is or am
grep -oE '<is>|am' super.txt
grep -E '(B|C)AT' super.txt