Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax error: redirection unexpected [duplicate]

I ran a deployment script to setup my server as root. Then I tried to run another script called test.sh which had the following lines in it:

# Logging
exec  > >(tee -a /var/log/test_full.log)
exec 2> >(tee -a /var/log/test_error.log)

However when I try this I get the following error:

test.sh: 19: test.sh: Syntax error: redirection unexpected

What might be causing this issue do you think? I've not heard of this error before.

like image 467
Jimmy Avatar asked Nov 24 '13 19:11

Jimmy


2 Answers

This answer solves your problem, assuming that your script snippet is complete.

In brief, you are running your script through dash, not bash. The solution is as simple as adding the necessary #!/bin/bash

What a system runs by default if the #! is missing varies from system to system. On my system, I don't get your error because a shell that understands your redirections is run by default. I've had to simulate the case where dash would be the default shell to reproduce your error.

like image 69
Louis Avatar answered Nov 08 '22 10:11

Louis


Assuming you run your script with ./myscript, make sure your scripts starts with

#!/bin/bash

and not #!/bin/sh or anything else. The error suggests that another shell than Bash is used.

If your script indeed do, check that /bin/bash is not a symbolic link and that it indeed is Bash with /bin/bash --version .

like image 10
damienfrancois Avatar answered Nov 08 '22 09:11

damienfrancois