if-else-fi
[jerry@localhost bin]$ cat if-else.sh #!/bin/bashdirectory="./hard_one"if [ -d $directory ]; then echo "Directory exists"else echo "Directory not exits"fi[jerry@loc...
#@ #$ #i
# "$#" number of args# "$@" all args [jerry@localhost bin]$ cat args_test.sh #!/bin/bashecho "This is all parameters: $@"echo "This is parameter one: $1"echo "This is the parameters number: $#"[jerry@...
Arrays
#!/bin/bashARRAY=('debian','ubuntu','fedora')ELEMENTS=${#ARRAY[@]}for ((i=0;i<$ELEMENTS;i++)); doecho ${ARRAY[${i}]}done-----NOTE: there are double "(" and ")" after "for"----[jerry@localh...
for loop
#!/bin/bashfor a in `seq 0 10`; doecho $adone[jerry@localhost bin]$ ./for_test.sh 0123456789101..10
bash trap
#!/bin/bash# bash trap commandtrap bashtrap INT# bash clear screen commandclear;# bash trap function is executed when CTRL-C is pressed:# bash prints message => Executing bash trap subrutine !bashtrap...
reading input to shell
!/bin/bashecho "Please type a word!"read wordecho "You just typed $word"echo "Please type two words!"read word1 word2echo "You just typed $word1 $word2"[jerry@localhost bin]$ ./reply_test.sh ./reply_t...
xecuting shell commands with bash
#!/bin/bash# use backticks " ` ` " to execute shell commandecho `uname -o`# executing bash command without backticksecho uname -o [jerry@localhost bin]$ ./echo.sh GNU/Linuxuname -o
global_variable VS local_variable &functional
#!/bin/bash#Define bash global variable#This variable is global and can be used anywhere in this bash scriptVAR="global variable"function bash {#Define bash local variable#This variable is local t...
Hello world
#!/bin/bash# declare STRING variableSTRING="Hello World"#print variable on a screenecho $STRINGNOTE: There is no space around both sides of "=".