0

So i am trying to create a script inside another script, but the issue i have encountered is that the variables in the script i am trying to create are getting filled by the script that is creating it. That is a little confusing, but i think it makes sense. Ill give an example...

#/bin/bash
cat <<EOF | tee -a ./newscript.sh
variable1=$(ls /home/ | wc -l)
variable2=$(expr $variable1 + 1)
EOF

The results of this script create a script that has those values filled out already, like this

variable1=*some number*
variable2=*another number*

The intended result would be to add that entire section of code into the script unchanged. How would I do this? My current workaround is just using wget to get the script from github, but i would much rather have it be all contained in one script without having to call out to another service to work. Thanks

  • The literal answer to your questions is to quote your heredoc (`<<'EOF'` instead of `< – Charles Duffy Oct 10 '22 at 17:35
  • oh wow okay thank you. that fixed the issue lol. for my application, this works much better than sourcing the script from elsewhere. but thanks for the answer! – scuffed_rayven Oct 10 '22 at 17:39

0 Answers0