0

I have a script (AWS EC2 instance user data) that must create another script:

#!/bin/bash
cat <<EOF > print.sh
#!/bin/bash
CMD="some AWS CLI command with output"
while [ "$CMD" != "in-use"]
do
   # wait 2 seconds
done
EOF

I expect the created script to look like that:

#!/bin/bash
while [ "$some command with output" != 'in-use']
do
   # wait 2 seconds
done

I need it like this because the command needs to be reevaluated every time the loop loops. To summarize, i need the while to execute the AWS CLI request every time. So far did manage to get it to while [ "" != "in-use"], while [ "in-use" != "in-use"] and while [ '' != 'in-use'] (and many similar outputs but not the one i need). Can you shed some light on how this even works, if its possible? Just to clarify, the command request will return either in-use or available but i need it checked every two seconds on subscript execution, not creation.

fixxxera
  • 205
  • 2
  • 10
  • quote the heredoc - `'EOF'` – Inian Feb 27 '20 at 18:36
  • 1
    Are you aware that your expected script has three bugs that will prevent it from executing correctly? Please avoid paraphrasing in code, and prefer to instead write a real demo script and copy-paste its output. It's confusing when you e.g. say that you expect double quotes to turn into single quotes, or that you expect to have "AWS CLI" automatically removed from your string – that other guy Feb 27 '20 at 18:55
  • Are you sure it's not supposed to be `CMD=$(some command)`? Normally that's how you capture the output of a command run in a subshell. – clearlight Feb 27 '20 at 20:48

0 Answers0