What syntax needs to be used in the following command in the terminal of a RHEL 8 AWS EC2 instance to return only the valid instance id instead of the corrupted value it is currently returning?

$ myinstid=$(curl
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    19  100    19    0     0   9500      0 --:--:-- --:--:-- --:--:--  9500
$ $myinstid
-bash: i-0u7t5y86blahblah: command not found

The value we want returned for $myinstid is i-0u7t5y86blahblah and NOT -bash: i-0u7t5y86blahblah: command not found.

1 Answer 1


You should echo the variable to output its value. echo "$myinstid"

You are setting the value of myinstid to the output of the command curl The output of the command in your case appears to be i-0u7t5y86blahblah. Then you are asking bash to run the variable myinstid in the shell, which for all intents and purposes here is the same thing as trying to run i-0u7t5y86blahblah as a command. This is why you are receiving the bash error i-0u7t5y86blahblah: command not found.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .