0

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 ?

hugogogo
  • 111
  • 3
  • The syntax to read a line of text is [`IFS= read -r line`](/q/209123), not `read line` and the syntax to output a line is [`printf '%s\n' "$line"`](/q/65803), not `echo "$line"`. But maybe even more importantly see: [Why is using a shell loop to process text considered bad practice?](//unix.stackexchange.com/q/169716) – Stéphane Chazelas Dec 15 '21 at 09:48
  • all right thank you :) – hugogogo Dec 15 '21 at 10:04

0 Answers0