i read a line from another file that contains a backslash, and i want to echo this line without expanding the backslash :
script.sh :
#!/bin/bash
while read line
do
echo "$line"
done < script_sample.txt
script_sample.txt :
echo \"
execution :
PROMPT> bash script.sh
echo "
PROMPT>
instead i would like :
PROMPT> bash script.sh
echo \"
PROMPT>
and i can't touch the lines inside script_sample.txt
, otherwise i would use single quotes '
or another backslash \
i really don't know how to do that ? i supposed it could be something like echo $'line'
or ${'line'}
that would expand the variable $line
but not its content, but i can't figure it out
maybe there is something to do with variable substitution ?
IFS= read -r line
, notread line
and the syntax to output a line isprintf '%s\n' "$line"
, notecho "$line"
. But maybe even more importantly see: Why is using a shell loop to process text considered bad practice? – Stéphane Chazelas Dec 15 '21 at 09:48