I have (roughly) the following code:

read -p "What is your variable: " WHATIS

cat > ./test.txt <<EOF

This should be a bunch of lines
I want this "variable" to be imbedded
it is ${WHATIS}

EOF

I keep getting the literal output of "${WHATIS}.
I did this ages ago but can not remember how or find the code I used.
Any help would be appreciated

All three of these options are working for me:

Plain echo "string" > file:

read -p "What is your variable: " WHATIS

echo "This should be a bunch of lines
I want this \"variable\" to be embedded
it is $WHATIS" > ./test.txt

cat with HEREDOC and variable expansion:

read -p "What is variable 2?: " WHATIS2

cat > ./test.txt <<EOF

This should be a bunch of lines
I want this "variable" to be embedded
it is $WHATIS2

EOF

cat withHEREDOC and variable substitution/expansion:

read -p "What is variable 3?: " WHATIS3

cat > ./test.txt <<EOF

This should be a bunch of lines
I want this "variable" to be embedded
it is ${WHATIS3}

EOF

Using ${var} instead of $var is for when you want the variable name separated from other content (like echo "${myvar}s are cool"), or when you are actually doing some extra substitution (like echo "${myvar:-mydefault}"). It doesn't hurt to use ${}, but it's not necessary.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.