Computer scienceSystem administration and DevOpsCommand lineBash syntax

Best practices for bash scripts

ShellCheck 2.0

Report a typo

Which suggestions do you get when you put the following script in ShellCheck?

#!/bin/sh
## Example: The shebang says 'sh' so shellcheck warns about portability
##          Change it to '#!/bin/bash' to allow bashisms
for n in {1..$RANDOM}
do
  str=""
  if (( n % 3 == 0 ))
  then
    str="fizz"
  fi
  if [ $[n%5] == 0 ]
  then
    str="$strbuzz"
  fi
  if [[ ! $str ]]
  then
    str="$n"
  fi
  echo "$str"
done
Select one or more options from the list
___

Create a free account to access the full topic