...
Code Block | ||
---|---|---|
| ||
# list 2 files, one that exists and one that does not ls ~/.profile xxx |
Produces this output in your terminal:
Code Block |
---|
ls: cannot access 'xxx': No such file or directory .profile |
...
Code Block | ||
---|---|---|
| ||
# Sets up auto-logging to a log file in the current directory # using the specified logFileTag (arg 1) in the log file name. auto_log() { local logFileTag="$1" if [[ "$logFileTag" != "" ]]; then local logFilePath="./autoLog_${logFileTag}.log" echo_se ".. logging to $logFilePath" exec 1> >(tee "$logFilePath") 2>&1 else echo_se "** ERROR in auto_log: no logFile argument provided" exit 255 fi } |
The general form of an if/then/else/fi statement is:
if [[ some_test ]]
then
what_to_do_when_some_test_is_true (0)
else
what_to_do_when_some_test_is_false (not 0)
fi
As always in bash, clauses (technically commands themselves) can be put on one line if separated by a semicolon ( ; ).
if [[ some_test ]]
; then echo "Test was true"; else echo "Test was false"; fi
testAutolog function and command processing
...