What is the difference between “$@” and “$*” in Bash? [duplicate]

The difference is subtle; “$*” creates one argument separated by the $IFS variable, while “$@” will expand into separate arguments. As an example, consider: for i in “$@”; do echo “@ ‘$i'”; done for i in “$*”; do echo “* ‘$i'”; done When run with multiple arguments: ./testvar foo bar baz ‘long arg’ @ ‘foo’ … Read more

How to remove a newline from a string in Bash

Under bash, there are some bashisms: The tr command could be replaced by // bashism: COMMAND=$’\nREBOOT\r \n’ echo “|${COMMAND}|” | OOT | echo “|${COMMAND//[$’\t\r\n’]}|” |REBOOT | echo “|${COMMAND//[$’\t\r\n ‘]}|” |REBOOT| See Parameter Expansion and QUOTING in bash’s man page: man -Pless\ +/\/pattern bash man -Pless\ +/\\\’string\\\’ bash man -Pless\ +/^\\\ *Parameter\\\ Exp bash man -Pless\ … Read more

Removing colors from output

According to Wikipedia, the [m|K] in the sed command you’re using is specifically designed to handle m (the color command) and K (the “erase part of line” command). Your script is trying to set absolute cursor position to 60 (^[[60G) to get all the OKs in a line, which your sed line doesn’t cover. (Properly, … Read more

Wait for a process to finish

To wait for any process to finish Linux (doesn’t work on Alpine, where ash doesn’t support tail –pid): tail –pid=$pid -f /dev/null Darwin (requires that $pid has open files): lsof -p $pid +r 1 &>/dev/null With timeout (seconds) Linux: timeout $timeout tail –pid=$pid -f /dev/null Darwin (requires that $pid has open files): lsof -p $pid … Read more