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
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
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
${var^}
(and by proxy,${var^^}
). Is there an equivalent to squash to lowercase? – DopeGhoti Jan 28 '16 at 22:05