Running the following script as myself works but not when I use sudo. As you can probably tell, the touch error is just to make sure something is written to the log file.
dave@pi1:~ $ ./test.sh
touch: cannot touch '/asdf/asdf/asdf': No such file or directory <--- As expected
dave@pi1:~ $ sudo ./test.sh
./test.sh: 2: ./test.sh: Syntax error: redirection unexpected <--- why this not work?
dave@pi1:~ $
The script:
LOG_FILE=/var/log/usbhook
exec > >(tee -a ${LOG_FILE} )
exec 2> >(tee -a ${LOG_FILE} >&2)
touch /asdf/asdf/asdf
The aim is to have a script fired when I plug in a USB stick so I'm assuming it should work when ran using sudo.
#!/usr/bin/env bashas first line in your script>(is a syntax element that can't be used in sh. Just because one operator is>( )and the other is<<<doesn't make it two different questions; it's the same misunderstanding about what it takes to ensure that bash-only syntax is available.