From b0daf0db5feb93e70e962823e4efb3a56f9d41dc Mon Sep 17 00:00:00 2001 From: Ian Wijma Date: Mon, 20 Nov 2023 23:40:56 +1100 Subject: [PATCH] Improve script safety by quoting variables and updating comparisons This commit updates the `test.sh` script to incorporate best shell scripting practices. Changes include quoting the variables "$SLEEP" and "$EXIT" to handle null or space-containing values better. The arithmetic comparison has been updated to use "bash-style" to improve the script's security. This refactoring aims to enhance the overall efficiency and reliability of the script execution. --- bin/test.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/test.sh b/bin/test.sh index bde7751..9d24533 100755 --- a/bin/test.sh +++ b/bin/test.sh @@ -1,18 +1,18 @@ #!/bin/bash -SLEEP=${1:-'10'} -EXIT=${2:-'0'} +SLEEP=${1:-10} +EXIT=${2:-0} echo "Sleeping for $SLEEP seconds..."; -sleep $SLEEP; +sleep "$SLEEP"; echo "Waking up!"; -if [ $EXIT > 0 ]; then +if [ "$EXIT" -gt "0" ]; then >&2 echo "Exiting with error code $EXIT"; else echo "Exiting with error code $EXIT"; fi -exit $EXIT; \ No newline at end of file +exit "$EXIT"; \ No newline at end of file