Bootstrap FreeKB - Bash (Scripting) - Resolve "root: command not found"
Bash (Scripting) - Resolve "root: command not found"

Updated:   |  Bash (Scripting) articles

Let's say you run a bash script and root: command not found is returned.

~]$ sudo /usr/local/scripts/example.sh
/usr/local/scripts/example.sh: line 2: root: command not found

 

In this example, the issue is on line 2 of the script.

~]$ cat /usr/local/scripts/example.sh | nl -ba | less
1  #!/bin/bash
2  $(ps -ef)

 

This was happening because I was using sudo to run the script. If I didn't use sudo, I got a slightly different output.

~]$ bash /usr/local/scripts/example.sh
/usr/local/scripts/example.sh: line 2: UID: command not found

 

If I then stored the output of the command in a variable, I no longer got the "command not found" output.

#!/bin/bash
stdout=$(ps -ef)

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 357191 in the box below so that we can be sure you are a human.