I have a script that I've simplified here:
#!/bin/bash
# test.sh
set -u
### test-script ###
cat <<SCRIPT > ~/test-file-output
#!/bin/bash
set -e
usage() {
cat <<EOF
Does a thing
EOF
}
for opt in "$@"; do
case $opt in
-h|--help)
usage
exit 0
;;
*)
echo "Invalid option: $opt" >&2
usage
exit 1
;;
esac
done
SCRIPT
chmod +x ~/test-file-output
and because the parent script has set -u
it is catching the opt
var in the child script in the heredoc; the child script sets opt
to the value of $@
.
Is there a way to get it to ignore all the vars and text in the heredoc since it's not part of the parent script itself? I thought it would treat the heredoc as a giant string and not parse it according to script syntax.