[英]Bash script eval with aws command producing "command not found"
我有一个简短的 bash 脚本可以从用户那里获取一个 int 来识别以选择某个 eks 集群。
当我使用eval $(aws eks --region us-east-1 update-kubeconfig --name eventplatform$input)
我收到错误: Updated: command not found
如果我只是将命令更改为aws eks --region us-east-1 update-kubeconfig --name eventplatform$input
,这个问题就解决了
为什么 eval 命令对此不起作用?
#!/usr/bin/env bash -e
read -p "Which cluster are you trying to access? (int >= 0): " input
while [[ -n ${input//[0-9]/} ]]
do
read -p "Which cluster are you trying to access? (int >= 0): " input
done
eval $(aws eks --region us-east-1 update-kubeconfig --name eventplatform$input)
简单的。 eval
参数应该是一个字符串或存在运行的东西,而不是其他注释的输出
#!/bin/bash
eval "ls" # okay
# file1.txt
# file2.txt
eval $(ls); # error
# bash: file1.txt: command not found
见help eval
eval: eval [arg ...] 将参数作为 shell 命令执行。
Combine ARGs into a single string, use the result as input to the shell, and execute the resulting commands.
eval
命令不应该为此工作(无论您期望“工作”在这种情况下意味着什么)。
eval
将数据作为代码运行。 只有将格式良好的 shell 命令或脚本作为数据写入其标准输出的程序才应该对该数据进行eval
编辑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.