I have a unix shell script which uses redirection of stdout and stderr to a log file. For example test.sh:
ls -l &>> test.log
My problem is that when I run the script with sudo:
sudo ./test.sh
The & is interpreted as “run in background”.
Any suggestions?
I guess, that your script
test.shdoes not have a shebang in the first line like this:Without this line several environment settings affect the way your script is executed. In your case this means that another shell like
ash,ksh,dashor whatever will be used to execute the script due to the setting of the root user.