Using Ubuntu Desktop, I have terminal open and I am using the bash shell. One of the shell expansions of bash is the arithmetic expansion, with the following syntax:
$(( EXPRESSION ))
or
$[ EXPRESSION ]
When i do arithmetic, it does return the correct value but it is always followed by "command not found":
$ $((1+2))
3: command not found
$ $[1+2]
3: command not found
$ $[2+2]
4: command not found
$ $((2*6))
12: command not found
My question is why does it display "command not found" and how can I fix that?
You have to add
echo
command before all of your commands,You don't have to put directly
$[1+2]
on terminal, because bash computes$[1+2]
and again parses the same, so command not found error occurs.For Example
In the above example,
sudo apt-get update
command was assigned to a variablevar
.On running$var
, first bash expands it and again parses the expanded one.What is happening here is that
bash
computes$((1+2))
which results in3
.bash
then looks for a command named3
to execute. It doesn't find it. Hence the error. As @Avinash suggests, useecho
to avoid this.Because
bash
is trying to execute the output of your expansion and it doesnt find anycommand
with name3
in thePATH
. To just try out, useecho
or assign it to a variable and use it later.