13

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.

0

2 Answers 2

19

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi. Sorry to be a pain but both files start with #!/bin/bash
Fact: when I run your test.sh script as bash test.sh there's no error, but when I run it with dash test.sh I get the exact error you get. For whatever reason exists on your system, it's not bash that is executing your script.
Ah, it's because I ran it "sh test.sh" I think!
11

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 .

5 Comments

As above, both files start with #!/bin/bash
What does /bin/bash --version output?
Thank you for the help but I solved it with both your helps and could only pick one answer im afraid but I hope the upvote helps :)
Fair enough, @Louis' comment was probably the element that led to solving the case. +1 for his answer and +1 for your question :)
+1 I've been in an environment where /bin/bash was a symbolic link to busybox, meaning the shell was ash and not bash...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.