I have a short bash script to take in an int from a user to identify to select a certain eks cluster.
When I use eval $(aws eks --region us-east-1 update-kubeconfig --name eventplatform$input)
I get the error: Updated: command not found
This is resolved if I simply change the command to just aws eks --region us-east-1 update-kubeconfig --name eventplatform$input
Why is the eval command not working for this?
#!/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)
CodePudding user response:
The eval
command isn't supposed to work for this (whatever you expect "work" to mean in this context).
eval
runs data as code. Only programs that write well-formed shell commands or scripts to their stdout as data should have that data eval
ed.
CodePudding user response:
Simple. eval
argument should be a string or something that exists to run, not output of other comments
#!/bin/bash
eval "ls" # okay
# file1.txt
# file2.txt
eval $(ls); # error
# bash: file1.txt: command not found
See help eval
eval: eval [arg ...] Execute arguments as a shell command.
Combine ARGs into a single string, use the result as input to the shell, and execute the resulting commands.