Simple completion using function _mycompletion() { local command_name="$1" # not used in this example local current_word="$2" local previous_word="$3" # not used in this example # COMPREPLY is an array which …
Devamını Oku..Process substitution
Compare two files from the web The following compares two files with diff using process substitution instead of creating temporary files. diff <(curl http://www.example.com/page1) <(curl http://www.example.com/page2) Feed a while loop …
Devamını Oku..Bash Script Scoping
Dynamic scoping in action Dynamic scoping means that variable lookups occur in the scope where a function is called, not where it is defined. $ x=3 $ func1 () { …
Devamını Oku..Bash Arithmetic
Parameter DetailsEXPRESSION Expression to evaluate Simple arithmetic with (( )) #!/bin/bash echo $(( 1 + 2 )) Output: 3 # Using variables #!/bin/bash var1=4 var2=5 ((output=$var1 * $var2)) printf "%d\n" …
Devamını Oku..Bash Script Math
Math using dc dc is one of the oldest programs on Unix. It uses reverse polish notation, which means that you first stack numbers, then operations. For example 1+1 iswritten …
Devamını Oku..Bash history substitutions
Quick Reference Interaction with the history # List all previous commands history # Clear the history, useful if you entered a password by accident history -c Event designators # Expands …
Devamını Oku..Scripting with Parameters
To parse lots of parameters, the prefered way of doing this is using a while loop, a case statement, and shift.shift is used to pop the first parameter in the …
Devamını Oku..Conditional Expressions
The -e conditional operator tests whether a file exists (including all file types: directories, etc.). if [[ -e $filename ]]; then echo "$filename exists" fi There are tests for specific …
Devamını Oku..Basc Script Quoting
Double quotes for variable and command substitution Variable substitutions should only be used inside double quotes. calculation='2 * 3' echo "$calculation" # prints 2 * 3 echo $calculation # prints …
Devamını Oku..Here Documents and Here Strings
Execute command with here document ssh -p 21 example@example.com <<EOF echo 'printing pwd' echo "\$(pwd)" ls -a find '*.txt' EOF $ is escaped because we do not want it to …
Devamını Oku..