Skip to main content
added 5 characters in body
Source Link
Stéphane Chazelas
  • 586.8k
  • 96
  • 1.1k
  • 1.7k

In newer versions of bash (since version 4.4 or so) there's yet another tricky way to indirectly expand variables in strings, without having to go full eval: the @P parameter transformation (= expand as in prompts, including but not limited to variable substitutions).

$ cat file.txt
${BLUE}hello blue${NORM}

$ BLUE=$'\e[34m'
$ NORM=$'\e[m'
$ while IFS= read -r line; do printf '%s\n' "${line@P}"; done < file.txt
hello blue

In newer versions of bash (since version 4.4 or so) there's yet another tricky way to indirectly expand variables in strings, without having to go full eval: the @P parameter transformation (= expand as in prompts, including but not limited to variable substitutions).

$ cat file.txt
${BLUE}hello blue${NORM}

$ BLUE=$'\e[34m'
$ NORM=$'\e[m'
$ while read -r line; do printf '%s\n' "${line@P}"; done < file.txt
hello blue

In newer versions of bash (since version 4.4 or so) there's yet another tricky way to indirectly expand variables in strings, without having to go full eval: the @P parameter transformation (= expand as in prompts, including but not limited to variable substitutions).

$ cat file.txt
${BLUE}hello blue${NORM}

$ BLUE=$'\e[34m'
$ NORM=$'\e[m'
$ while IFS= read -r line; do printf '%s\n' "${line@P}"; done < file.txt
hello blue
added 93 characters in body
Source Link
user313992
user313992

In newer versions of bash (since version 4.4 or so) there's yet another tricky way to indirectly expand variables in strings, without having to go full eval: the @P parameter transformation (= expand as in promptsprompts, including but not limited to variable substitutions).

$ cat file.txt
${BLUE}hello blue${NORM}

$ BLUE=$'\e[34m'
$ NORM=$'\e[m'
$ while read -r line; do printf '%s\n' "${line@P}"; done < file.txt
hello blue

In newer versions of bash (since version 4.4 or so) there's yet another tricky way to indirectly expand variables in strings, without having to go full eval: the @P parameter transformation (= expand as in prompts, including but not limited to variable substitutions).

$ cat file.txt
${BLUE}hello blue${NORM}

$ BLUE=$'\e[34m'
$ NORM=$'\e[m'
$ while read -r line; do printf '%s\n' "${line@P}"; done < file.txt
hello blue

In newer versions of bash (since version 4.4 or so) there's yet another tricky way to indirectly expand variables in strings, without having to go full eval: the @P parameter transformation (= expand as in prompts, including but not limited to variable substitutions).

$ cat file.txt
${BLUE}hello blue${NORM}

$ BLUE=$'\e[34m'
$ NORM=$'\e[m'
$ while read -r line; do printf '%s\n' "${line@P}"; done < file.txt
hello blue
Source Link
user313992
user313992

In newer versions of bash (since version 4.4 or so) there's yet another tricky way to indirectly expand variables in strings, without having to go full eval: the @P parameter transformation (= expand as in prompts, including but not limited to variable substitutions).

$ cat file.txt
${BLUE}hello blue${NORM}

$ BLUE=$'\e[34m'
$ NORM=$'\e[m'
$ while read -r line; do printf '%s\n' "${line@P}"; done < file.txt
hello blue