When I use "cat test.file", it will show
printf "This is a test log %d \n, testid";
1
2
When I use the bash file,
IFS=""
while read data
do
echo "$data"
done << test.file
It will show
printf "This is a test log %d n, testid";
1
2
The "\" is gone.
Is there any way that I can keep the "\" and space at the same time?
Try using read -r
.
From the man page:
-r
If this option is given, backslash does not act as an escape character. The backslash is considered to be part of the line. In particular, a backslash-newline pair may not be used as a line continuation.
Execute this to test it:
read -r a < <(echo "test \n test"); echo $a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With