Зачастую нужно из файла передать всякую нечитабельную хрень
куда-то дальше. Для этого нужно квотировать. В баше-2020
теперь есть специальные шаблоны: ${var@Q} и ${var@A}
$ var=$'Hello world.n'
$ echo "$var"
Hello world
$ echo "${var@Q}"
$'Hello world.n'
$ echo "${var@A}"
var=$'Hello world.n'
${parameter@operator}
Parameter transformation. The expansion is either a transforma‐
tion of the value of parameter or information about parameter
itself, depending on the value of operator. Each operator is a
single letter:
Q The expansion is a string that is the value of parameter
quoted in a format that can be reused as input.
...
A The expansion is a string in the form of an assignment
statement or declare command that, if evaluated, will
recreate parameter with its attributes and value.
А по старинке это делалось с помощь printf "%q". Пример:
# Квотируем a -> x
while read -r a
do
printf -v x "%q" "$a"
agrep -n "$x" text.txt >> result
done < somefile
Bash Справочник v0.05 © 2007-2026 Igor Salnikov aka SunDoctor