【问题标题】:Error when exporting the result of a valid command as a bash variable将有效命令的结果导出为 bash 变量时出错
【发布时间】:2016-03-03 23:08:12
【问题描述】:

我正在尝试将命令行的结果导出为环境变量。这是我的做法:

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

但是,当我运行 bash 文件时,出现以下错误:

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

 ^

该命令是有效的,因为当我直接从命令行尝试它时它会起作用。知道为什么会出现此错误吗?

【问题讨论】:

  • 你在调用文件时到底输入了什么?
  • 我这样称呼./mybashfile option,它是我已经chmod +x mybashfile的可执行文件
  • 文件顶部有什么?您可能需要包含#!/bin/bash
  • 是的,我有这个 shebang,我的 bash 工作正常,只是当我添加上面的命令时,我在运行它时会出错

标签: macos bash amazon-web-services command-line environment-variables


【解决方案1】:

我不得不将整个命令放在一行中,我不知道为什么 \ 会导致问题!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-22
    • 1970-01-01
    • 2014-02-19
    • 2020-12-19
    • 1970-01-01
    • 1970-01-01
    • 2011-01-23
    相关资源
    最近更新 更多