Bash Everywhere, The Receipe Of Progressive To Mastery; Like Javascript;

Keep writing one type of lang even when you have got bored, and keep spreading mind to different perspectives of the lang leads to deeper impression.



1. how to declare variable;

2. how to declare array; either declare an array name declare -a arr; or use assignment; += to add to array; unset $arr[2] to delete; $arr[@]/$arr[*] to represent all members of array;(el1 el2), {el3,el4,el5}, bash version;  declare revelant array, declar -A relevantArray only available above bash version 4?, arr[0]; traverse: for i in ${arra[*]}; get length of array: echo ${#array1[@]},

array[index_abc]=33; echo $array[index_abc];

3. for (( ; ; )); do sth;done;, double brackets; white space everywhere; if sth;then sth; fi; 

4. check operators: -eq, -gt -lt, -d, -f, ! , -nt, -ot, -n, `expr length astring`

5. sleep 5, by default by second;

6. read user input: echo "pls input:" ;read avariable; echo $avariable;

7. bash case $userinput in Y|y)echo $userinput;;in N|n)echo "n";; esac


#Example for bash split string by Symbol (comma) read -p "Enter Name, City and Age separated by a comma: " entry #reading string value IFS=',' #setting comma as delimiter read -a strarr <<<"$entry" #reading str as an array as tokens separated by IFS 

readarray -d : -t strarr <<<"$str" #split a string based on the delimiter ':' 


d=`date +%m-%d-%Y`

echo "Do you know Java Programming?" read -p "Yes/No? :" Answer case $Answer in Yes|yes|y|Y) echo "That's amazing." echo ;; No|no|N|n) echo "It's easy. Let's start learning bash." ;; esac 

[[]]]  supports regular expression
chmod o+w,o+x



Leave your comment