i am not being able to compile his code as it is failing and says "/bin/sh: make command not found" can someone tell me what this means? i am new to shell scripting and i have no idea what is the problem...
Several problems in that statement:
- "compile this code" ... a Bash script doesn't need to be compiled. Bash is an interpreted language
- "/bin/sh: make command not found" means exactly what it looks like: the
make
command is not found. You don't have a make
command on your PATH
. But it doesn't matter, because you don't need make
here
Your script has syntax errors, for example:
if ["$x " -lt "$y"]
You need to put a space after [
and before ]
, like this:
if [ "$x " -lt "$y" ]
Other problems:
- Not using
if-elif-else
for the 3 cases
- Broken conditions: there are 2
if
but only 1 closing fi
A few other tips:
- For doing arithmetic in Bash, use
((...))
instead of [...]
.
- Instead of
echo -n; read
, use read -p
: it's one command instead of two, and the flags of echo
are not portable, so it's better to avoid using them
- Indent the content of
if-elif-else
to make the script easier to read
With the corrections and improvements applied:
#!/usr/bin/env bash
read -p "enter the first number: "
read -p "enter the second number: "
if ((x < y)); then
echo "$x < $y"
elif ((x > y)); then
echo "$y < $x"
else
echo "$x == $y"
fi