Following up on your previous question, it sounds like you want both some uninterpreted text and some interpreted text going into a file. In that case, use two different
cat > /test <<'EOF'
some uninterpreted text $(pwd)
not substituted: $1
cat >> /test <<EOF
but this will substitute: $1
There's a couple of things going on here: firstly, the heredoc syntax with
<<. If you include quotes in that terminator string, as in the first one above, the entire heredoc is uninterpreted — no parameters and no substitutions. If you don't use any quotes, like in the second
cat above, variables like
$1 will be replaced by their values and command substitutions will be included in the text. You choose between whether to quote the "EOF" string or not based on whether you want substitutions or not.
To put both
cats into the same file we're using
>> redirection for the second (and any later) redirections: that means to append to the file. For the first one, we use a single
> to clear the file out and start fresh.
Note that, even when variables are substituted, any additional dollar signs in that variable's value aren't re-substituted themselves:
without substituting in
However, if you're providing a "$" in the argument to this whole script, you need to escape it on the command line or enclose the whole thing in single quotes. Alternatively, command substitution as in your other question lets you put the contents of a whole file in directly, including any dollar signs in the file contents. Make sure you quote the substitution string there:
oo.sh "$(cat myfile)"
will get the body of
$1 and can then
echo it as required. The same limitations as in my answer there apply: there's a limit for how long the command-line arguments can be, and if your file might get longer than that you should find another approach. You can find out what the limit is on your system with