ERR=$(ping 8.8.8.8 -c 5 2>&1 >/dev/null ) && echo "OK" || { echo "FAILED: ${ERR}" && exit; }
Command substitution allows the output of a command to replace the command name. There are two forms:
$(command)
or
`command`
Bash performs the expansion by executing command and replacing the command substitution with the standard output of the command
$ cat a.sh
#!/bin/bash
DOTSTRING=".................................................."
function align_left() {
local chars="$1"
local str="${@:2}"
echo -n ${str}${chars:${#str}}
}
align_left $DOTSTRING "Hello"; echo "OK"
align_left $DOTSTRING "BigBigString"; echo "OK"
$ ./a.sh
Hello.............................................OK
BigBigString......................................OK
$