Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Удаленная работа для IT-специалистов
O=`ping 8.8.8.8 -c 5 2>&1 > /dev/null` && echo "OK" || { echo "FAILED: $O" && exit; }
printf "FAILED:\n$O\n"
echo "FAILED:" echo "$O"
ERR=$(ping 8.8.8.8 -c 5 2>&1 >/dev/null ) && echo "OK" || { echo "FAILED: ${ERR}" && exit; }
{ echo "FAILED:" && echo "${ERR}" && exit; }
{ echo -e "FAILED:\n${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
{ echo -n "FAILED:\n${ERR}" && exit; }
$ echo -e "String1\nString2" String1 String2
$ ./script.sh Hello.............................................OK BigBigString......................................OK
$ 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 $