Bugs:
echo "$my_variable" | my_command
can behave unexpectedly if the variable starts with one of theecho
options. You can domy_command <<< "$my_variable"
instead.unset $IFS
does not unsetIFS
. For that you needunset IFS
.
Simplifications:
- You shouldn't need to set
IFS
-read
will save the full input to the variable anyway (seehelp [r]ead
). - A lot of the code is already Python, and Python has much fewer caveats than Bash, so changing to it would very much benefit the maintainability of the code. Strictly speaking it's not a pure Bash script anyway, and you really don't want to be parsing JSON manually in Bash. If you really need a Bash script (which you shouldn't unless it's for a Bash programming exercise, and even then, somebody is wrong on the Internet if they asked you to use pure Bash to parse JSON) you could make it a wrapper script.
- Bash's
read
takes a-p prompt
option, so you can avoid the firstprintf
. - Unchanging variables such as
URL
should be assigned outside of the loop.
Style issues:
- Non-exported variables should be lowercase to distinguish them from exported variables.
- It is customary to
exit
with a non-zero exit code when a command fails.