2

I am trying to run

diff <(tar -tvf HIVE_CLIENT.tar.gz | sort) <(tar -tvf YARN_CLIENT.tar.gz | sort) 

putting this command inside script, when I execute script it shows error

syntax error near unexpected token `(' "

But when I do not put inside script rather than run from shell directly it works.

1
  • 1
    Show shebang of your script and how do you run this script. Commented Sep 25, 2017 at 8:28

2 Answers 2

1

Probably your script is run with /bin/sh and not with /bin/bash, but command substitution is a bash feature and not implemented in sh. So I suppose you are using bash as your shell which is why it is working from the command line.

Try adding this prefix to your script, and remove existing shebangs (like #!/bin/sh or similar):

#!/bin/bash
Sign up to request clarification or add additional context in comments.

Comments

1

You should try following two actions:

  1. Use #!/bin/bash as your shebang (First line of your script)

  2. This may be needed based on your bash, use only if opetion 1 does not help. Use following commands to flip between posix mode which is needed for process substitution:

    set +o posix 
    diff <(tar -tvf HIVE_CLIENT.tar.gz | sort) <(tar -tvf YARN_CLIENT.tar.gz | sort)
    set -o posix
    

    Example:

    wc -l <(ls -lrt)
    sh: syntax error near unexpected token `('
    
    set +o posix  
    wc -l <(ls -lrt)
    114 /dev/fd/00
    
    set -o posix
    wc -l <(ls -lrt)
    sh: syntax error near unexpected token `('
    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.