0

I have been trying for a long time to get this basic bit of code to work in a shell script, but to no avail, the code doesn't work!

read dec
if [ dec="Y"]||[dec="Y"]||[dec="y" ]; then
let repeat=1;
else
let repeat=0;
fi
done
Michael Mrozek
  • 93,103
  • 40
  • 240
  • 233

1 Answers1

7

You need spaces on either side of the [ and ] characters, since they are commands, not operators.

You also don't need let, and you need to read dec as a variable (i.e. $dec).

You can also uppercase the variable just for the test, so you don't need to test against both upper (twice!) and lower case results.

You don't need the done at the end, either, since there's no loop.

read dec
if [[ "${dec^}" = "Y" ]]; then
  repeat=1
else
  repeat=0
fi