input() {
read -p $'\e[31m\e[1m $1 [Y/n] \e[0m' -n 1 -r
}
input "test"
exit
This just prints "$1" in as the line of text. Why isn't it printing "test" and how can I make it do so?
input() {
read -p $'\e[31m\e[1m $1 [Y/n] \e[0m' -n 1 -r
}
input "test"
exit
This just prints "$1" in as the line of text. Why isn't it printing "test" and how can I make it do so?
The problem is that variables are not expanded inside single quotes. You are looking for this:
read -p $'\e[31m\e[1m '"$1"$' [Y/n] \e[0m' -n 1 -r
See that only the escape sequences are single quoted now, while $1 is double quoted.