Why does the status variable not take the value of the cat command as written, knowing that the cat command before the right content? I have been looking for some hours now : check the lines with (*)
if [ ! -f "node.txt" ]; then
     echo " File computes_to_delete not found"
     exit 1;
fi
while read -r compute_to_delete; do
    compute_to_delete=${compute_to_delete}
    compute_sh=${compute_to_delete}.sh
    { cat << EOF;} > "$compute_sh"
#!/bin/bash
echo "compute to be deleted"
echo  $compute_to_delete
openstack compute service list
openstack compute service set $compute_to_delete nova-compute --enable
openstack compute service list --long -c Binary -c Host -c Status -f json | jq -r '.[] | select(.Host == "$compute_to_delete" ) | .Status' > status.txt
(*) cat status.txt
(*) STATUS=$(< status.txt)
echo "$STATUS"
if [ "$STATUS" == "enabled" ]; then
fi
openstack server list --host $compute_to_delete --all-projects
EOF
done < computes_hosts.txt
As suggested in the comments, I've added backslashes before the concerned variable and now its working fine
if [ ! -f "node.txt" ]; then
     echo " File computes_to_delete not found"
     exit 1;
fi
while read -r compute_to_delete; do
    compute_to_delete=${compute_to_delete}
    compute_sh=${compute_to_delete}.sh
    { cat << EOF;} > "$compute_sh"
#!/bin/bash
echo "compute to be deleted"
echo  $compute_to_delete
openstack compute service list
openstack compute service set $compute_to_delete nova-compute --enable
openstack compute service list --long -c Binary -c Host -c Status -f json | jq -r '.[] | select(.Host == "$compute_to_delete" ) | .Status' > status.txt
 cat status.txt
 STATUS=\$(< status.txt)
echo "\$STATUS"
if [ "\$STATUS" == "enabled" ]; then
fi
openstack server list --host $compute_to_delete --all-projects
EOF
done < computes_hosts.txt
 
    