tags:

views:

67

answers:

4

Simply I need to write

"echo" t${count} = "$"t${count}"

To a text file, including all the So the output would be something like:

echo "  t1  = $t1"

With " as they are. So I have tried:

count=1
saveIFS="$IFS"
IFS=$'\n'
array=($(<TEST.txt))
IFS="$saveIFS"
for i in "${array[@]}"
do
echo "echo" t${count} = "$"t${count}""
(( count++ ))
done >> long1.txt

And variations on this such as:

echo "echo" """"" t${count} = "$"t${count}""

But I guess the wrapping in double " is only for variables.

Ideas?

+5  A: 

There's actually no wrapping in double quotes for variables, first quote starts, the second quote ends the quoted string. You may however concatenate strings however you want, so "$"t${count}"" will actually be equivalent to "$"t${count}, beginning with a quoted $-sign, followed by 't', followed by the count-variable.

Back to your question, to get a ", you can either put it in a literal string (surrounded by single quotes), like so echo '"my string"', note though that variables are not substituted in literal strings. Or you can escape it, like so echo "\"my string\"", which will put a literal " in the string, and won't terminate it.

roe
+1  A: 

You need to escape the doublequote (also dollar sign):

echo "\" t = \$t\""
Pasi Savolainen
+2  A: 
echo "echo \"t${count} = $t${count}\""
ghostdog74
+1  A: 

Yet another quoting variant (more of an exercise than a solution of course):

# concatenate alternating single- & double-quoted blocks of substrings
count=1
echo 'echo "t'"${count}"' = $t'"${count}"'"' 
trfin