To avoid \n:
using "printf" rather than "echo"
Set String
IFS='' read -r -d '' V <<'EOF'
'^+%&/%+^
EOF
Test w/ echo ( works fine )
echo "$V"
'^+%&/%+^
Test w/ printf ( fails )
printf "$V"
bash: printf: `&': invalid format character
To avoid \n:
using "printf" rather than "echo"
Set String
IFS='' read -r -d '' V <<'EOF'
'^+%&/%+^
EOF
Test w/ echo ( works fine )
echo "$V"
'^+%&/%+^
Test w/ printf ( fails )
printf "$V"
bash: printf: `&': invalid format character
The first argument to printf
will be interpreted as a formatting string, and %&
is an invalid format specifier.
Try this instead:
printf '%s' "$V"
The formatting that printf
does should be explained in the printf(1)
manual, or in the manual of your shell. The %s
format simply means "expect a string". The printf
utility does not add a newline by default.