The TLDR answer:
If you need to use a shell script which would create a file with the dynamic content using few variables then you can use the code below. The approach we shall take here will use heredoc / here document syntax.
cat << EOF > demo.txt
cd