I'm trying to export the result of a command line as en environment variable. Here is how I'm doing it:

group_id=$(aws ec2 describe-security-groups --filters Name=group-name,Values=${group_name} \
  | jq '.["SecurityGroups"][0].GroupId' \
  | sed -e 's/^"//'  -e 's/"$//'

However when I run the bash file, I get the following error:

Error parsing parameter '--filters': Expected: '=', received: 'EOF' for input:


The command is valid, as it works when I try it directly from the command line. When I use set -exv on the top of this bash file, I get the content of the file then:

+ case $1 in
+ init
aws ec2 describe-security-groups --filters Name=group-name,Values=${group_name} \
++ aws ec2 describe-security-groups --filters Name=group-name,Values=docker-networking ' '

Error parsing parameter '--filters': Expected: '=', received: 'EOF' for input:

+ group_id=

Any idea why I'm getting this error?

  • 1
    Can you run your script with set -xv? – choroba Nov 30 '15 at 11:39
  • @choroba i've updated the question after setting set -xv – bachr Nov 30 '15 at 12:02
  • 2
    Does it work if you put the whole pipe on one line? – choroba Nov 30 '15 at 12:15
  • Ah it worked, but what's the problem with the `\`? – bachr Nov 30 '15 at 12:22
  • I have no idea. Is the \ really the last character at the line? – choroba Nov 30 '15 at 12:30

There seems to be a space after the backslash. To make multiline commands, the backslash must be the very last character on a line.

Deduced from the output of set -xv:

++ aws ec2 describe-security-groups --filters Name=group-name,Values=docker-networking ' '
                                                                              here ->  ~~~

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.