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..Bash Script Sourcing
Sourcing a file Sourcing a file is different from execution, in that all commands are evaluated within the context of the currentbash session – this means that any variables, function, …
Devamını Oku..Bash Script Using sort
OptionMeaning-uMake each lines of output unique Sort command output sort command is used to sort a list of lines. Input from a file sort file.txt Input from a command You …
Devamını Oku..Bash Script Copying (cp)
OptionDescription-a,-archiveCombines the d, p and r options-b, -backupBefore removal, makes a backup-d, –no-deferencePreserves links-f, –forceRemove existing destinations without prompting user-i, –interactiveShow prompt before overwriting-l, –linkInstead of copying, link files instead-p, …
Devamını Oku..Bash Parameter Expansion
The $ character introduces parameter expansion, command substitution, or arithmetic expansion. The parameter name or symbol to be expanded may be enclosed in braces, which are optional but serve to …
Devamını Oku..Bash Script Functions
Functions with arguments In helloJohn.sh: #!/bin/bash greet() { local name="$1" echo "Hello, $name" } greet "John Doe" # running above script $ bash helloJohn. Hello, John Doe If you don’t …
Devamını Oku..Bash Script Associative arrays
Examining assoc arrays All needed usage shown with this snippet: #!/usr/bin/env bash declare -A assoc_array=([key_string]=value \ [one]="something" \ [two]="another thing" \ [ three ]='mind the blanks!' \ [ " four" …
Devamını Oku..Bash Sctipt Arrays
Array Assignments List Assignment If you are familiar with Perl, C, or Java, you might think that Bash would use commas to separate array elements,however this is not the case; …
Devamını Oku..