User Tools

Site Tools


bash_notes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
bash_notes [2021/07/29 23:47] – [getopts] adminbash_notes [2023/12/28 08:46] – [useful links] raju
Line 1: Line 1:
 +===== tasks =====
 +==== dummy ====
 +  * [[list files within a specific range]]
 +
 ===== dummy ===== ===== dummy =====
 +==== other pages in this wiki ====
 +  * [[bash scripting]]
 +
 ==== useful links ==== ==== useful links ====
-  * https://mywiki.wooledge.org/ArithmeticExpression - Arithmetic Expansion +  * https://explainshell.com/ - useful for understanding complex shell commands 
 +  * https://mywiki.wooledge.org/ArithmeticExpression - Arithmetic Expansion 
 +  * https://misc.flogisoft.com/bash/tip_colors_and_formatting - escape characters, color prompts, echo colored strings 
 +  * http://ezprompt.net/ - Easy bash prompt generator 
 + 
 +==== documentation links ==== 
 +  * ignoredups, erasedups - https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html search for ignoredups . 
 + 
 +==== what is the difference between "ls > dirlist 2>&1" and "ls 2>&1 > dirlist"? ==== 
 +The command 
 +<code> 
 +ls > dirlist 2>&
 +</code> 
 +directs both standard output (file descriptor 1) and standard error (file descriptor 2) to the file dirlist, while the command 
 +<code> 
 +ls 2>&1 > dirlist 
 +</code> 
 +directs only the standard output to file dirlist, because the standard error was made a copy of the standard output before the standard output was redirected to dirlist. 
 + 
 +To conclude, the order of redirections is significant. 
 + 
 +Ref:- https://www.gnu.org/software/bash/manual/html_node/Redirections.html -> 5th paragraph. 
 ===== getopts ===== ===== getopts =====
 ==== useful articles ==== ==== useful articles ====
Line 108: Line 137:
  
 search tags | string concatenation multiple spaces search tags | string concatenation multiple spaces
 +
 +==== stackoverflow links I came across ====
 +  * https://stackoverflow.com/questions/18668556/how-can-i-compare-numbers-in-bash
 +      * check if a number is greater than something
 +      * compare numbers
 +
 +==== add an element to an array ====
 +
 +<code>
 +appliances=("AC" "TV" "Mobile" "Fridge" "Oven" "Blender")
 +appliances+=("Dish Washer")
 +for appliance in "${appliances[@]}"
 +do
 +     echo $appliance
 +done
 +</code>
 +
 +<code>
 +languages=("PHP" "MySQL" "Bash" "Oracle")
 +languages[${#languages[@]}]="Python"
 +for language in "${languages[@]}"
 +do
 +     echo $language
 +done
 +</code>
 +
 +<code>
 +fruits=("Banana" "Mango" "Watermelon" "Grape")
 +fruits=(${fruits[@]} "Jack Fruit")
 +for fruit in "${fruits[@]}"
 +do
 +     echo $fruit
 +done
 +</code>
 +
 +<code>
 +men=("John" "Watson" "Micheal")
 +women=("Lisa" "Ella" "Mila")
 +people=(${men[@]} ${women[@]})
 +
 +for person in "${people[@]}"
 +do
 +     echo $person
 +done
 +</code>
 +
 +Ref:-
 +  * https://linuxhint.com/bash_append_array/ - well written but the information density is low. So I just summarized the points here and renamed the variables a bit.
 +  * https://stackoverflow.com/questions/1951506/add-a-new-element-to-an-array-without-specifying-the-index-in-bash
  
bash_notes.txt · Last modified: 2023/12/28 08:49 by raju