Bash-Script Error 0=1: Command Not Found

Bash-Script Error 0=1: command not found

In this line:

${nutzerVerzeichnis}="1"

You are telling it to evaluate to the value of nutzerVerzeichnis which is 0. Therefore it is the same as writing.

0=1

if your trying to assign it a value instead then leave off the ${} to this

nutzerVerzeichnis="1"

There are also a few other mistakes in your code. Here is the corrected code.

#!/bin/bash
users=(Hans Peter Alfred Georg Stefan Albert Christine)
for user in "${users[@]}";
do
nutzerVerzeichnis="0"
if [ -d "/home/${user}" ]
then
nutzerVerzeichnis="1"
echo "$home_dir"
fi

if [ "${nutzerVerzeichnis}" -eq "1" ]
then
echo "Home ${user} ok" >> /root/skript/permission.log
else
echo "Home ${user} Error" >> /root/skript/permission.log
fi
done
exit 0

if[ 0 -lt 1] command not found error in shell script

You need a space between if and [. You'll have the same issue after while.

The [ ] notation is kind of an oddity in shell. It looks like part of the language, but it actually isn't. The if and while words always need to be followed by whitespace and then a command, which is executed, and considered to be true or false according to whether its exit code is zero or nonzero.

So there is actually a command named [ which evaluates the conditions given on its command line, and terminates with an exit code according to whether the condition evaluated true or false. You can see an executable in the /usr/bin directory on most systems (though the shell usually has a built-in version for efficiency). It works the same as test.

Also, keep in mind that if needs a matching fi after the else clause.

[0: command not found in Bash

Need a space after [ and no space before or after = in the assignment. $(($i+1))) would try to execute the output of the ((...)) expression and I am sure that's not what you want. Also, you are missing a $ before the array name.

With these things corrected, your while loop would be:

#!/bin/bash
i=0
while [ "$i" -le "${#myarray[@]}" ]
do
echo "Welcome $i times"
i=$((i + 1))
done
  • i=$((i + 1)) can also be written as ((i++))
  • it is always better to enclose variables in double quotes inside [ ... ]
  • check your script through shellcheck - you can catch most basic issues there

See also:

  • Why should there be a space after '[' and before ']' in Bash?
  • How to use double or single brackets, parentheses, curly braces
  • Command not found error in Bash variable assignment
  • Using [ ] vs [[ ]] in a Bash if statement

bash error : =0: command not found

$OUT=$1
^

You probably want to drop the $.

Getting command not found error in bash script

The problem is that you are redefining the PATH variable where bash looks into to find the binary files if you don't use a complete path when calling.

You should change the PATH in your bash script to MYPATH or something like that, so that it doesn't mess with the already environmental variables.

If you don't know what the PATH variable is for you can look at wikipedia's article

Bash script command not found error in while loop

You are missing space near square brackets used in while loop such as below -

declare -i disk_usage_rate=$(df -h /appdata/SCT_CDR | cut -d '%' -f 1 | awk 'NR==2{print $5}')

while [ "$disk_usage_rate" -gt 80 ]
do
...
...
done

A bit of history: this is because '[' was historically not a
shell-built-in but a separate executable that received the expresson
as arguments and returned a result. If you didn't surround the '['
with space, the shell would be searching $PATH for a different
filename (and not find it) . – Andrew Medico Jun 24 '09 at 1:13

Ref - bash shell script syntax error

Getting command not found error while comparing two strings in Bash

This is problem:

if [[$variable == $blanko]];

Spaces are required inside square brackets, use it like this:

[[ "$variable" == "$blanko" ]] && echo "Nichts da!" || echo "$variable"

Why is $(( sum += i )) in bash telling me command not found?

Drop the $ in front:

((sum+=i))

$(()) will do arithmetic expansion, and the result of the expansion would be treated as a command to run leading to the error messages.



Related Topics



Leave a reply



Submit