0

As a part of my bash routine I am printing some message in terminal regarding status of the workflow. The message in splited into two parts (part 1: begining of the task, part 2: status of its finishing)

echo -n "Dataset is being processed ! "; execution of some AWK script; echo " Processing has been COMPLETED!"

Here is realisation in bash contained a part of the AWK code:

# print pharase 1: initiation of the process
echo -n "Dataset is being rescored.. Please wait"; sleep 0.5 
# this is the process: makedir for the result and execute AWK code to process input file
mkdir ${results}
# Apply the following AWK code on the directory contained input file
while read -r d; do
awk -F, '
}'  "${d}_"*/target_file.csv > "${results}/"${d%%_*}".csv"
done < <(find . -maxdepth 1 -type d -name '*_*_*' | awk -F '[_/]' '!seen[$2]++ {print $2}')
# print pharase 2: finish of the result, which would appear in the terminal near phrase 1
# this will print "COMPLETED" letter-by-letter with the pause of 0.2 sec between each letter
echo -n " C"; sleep 0.2; echo -n "O"; sleep 0.2; echo -n "M"; sleep 0.2; echo -n "P"; sleep 0.2; echo -n "L"; echo -n "E"; sleep 0.2; echo -n "T"; echo -n "E"; sleep 0.2; echo "D!"

While executing this script in bash, everything seems to be OK and I have not noticed any problems related to the parts of the code between both 'echo -n' blocks. May such splitting of the status phrase using "echo -n" lead to some bugs of the routine in bash ?

8
  • Do you have anything specific in mind that could be a problem? By definition such status messages are always split since they occur as/when things happen in your script. You should be printing them to stderr instead of stdout though (add >&2s) and the usual advice is to use printf instead of echo for any printing (see unix.stackexchange.com/a/65819/133219). Commented Apr 29, 2021 at 13:47
  • 1
    Are you planning to annoy only yourself with those added sleep delays? or other people? because I guarantee you that no matter how cool you think they are, other users will hate them (and you) for costing them valuable seconds, and the more often they have to run the script the greater their hate will grow. 300bps modems were not fun, and 0.2 seconds per char is ~5 times slower. If you insist on doing it, at least write a function. eg. slowprint () { for c in "$@" ; printf "%s" "$c" ; sleep 0.2 ; done ; printf "\n" ; }. Then you can run slowprint C O M A T O S E whenever you want. Commented Apr 29, 2021 at 14:55
  • bravo, thank you very much very cool sollution! but there is a bug somewhere: ./rmyscript.sh: line 107: syntax error near unexpected token `printf' Also should I add somewhere there >&2 (according to the previous comment) in order to send the message to stderr instead of stdout ? Commented Apr 29, 2021 at 15:19
  • 2
    it's not a bug in the function, it's a bug in your use of it. Use single-quotes around asterisks and other shell meta-characters, to prevent the shell from expanding them. e.g. slowprint '*' '*' '*' '*' '*'. and, yes, i forgot the do in the for loop, your version fixed it. Commented Apr 29, 2021 at 17:10
  • 3
    Always paste your script into https://shellcheck.net, a syntax checker, or install shellcheck locally. Make using shellcheck part of your development process. Commented Apr 29, 2021 at 17:19

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.