Syntax Error: Unexpected Redirection

I ran a deployment script to configure 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 to do this, I get the following error:

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

What could be the cause of this problem, do you think? I have not heard about this error yet.

+6
source share
2 answers

This answer solves your problem, assuming your script fragment is complete.

In short, you are using a script through dash , not bash . The solution is as simple as adding the necessary #!/bin/bash

What the system starts by default if #! missing #! depends on system to system. On my system, I am not getting your error, because a shell that understands your redirects starts by default. I had to simulate the case where dash will be the default shell to reproduce your error.

+11
source

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

 #!/bin/bash 

not #!/bin/sh or anything else. The error assumes that a different shell is used than Bash.

If your script is valid, make sure /bin/bash not a symbolic link and that it is really Bash with /bin/bash --version .

+7
source

Source: https://habr.com/ru/post/958732/


All Articles