Bash (Scripting) - Resolve "root: command not found"
by
Jeremy Canfield |
Updated: August 09 2023
| 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