Lines 8.and 9.below mix me up:
#!/bin/bash
a=foo
b=6
c=a
d="\e[33m" # opening ansi color code for yellow text
e="\e[0m" # ending ansi code
f=$d
printf "1. foo\n"
printf "2. $a\n"
printf "3. %s\n" "$a"
printf "4. %s\n" "${!c}"
printf "5. %${b}s\n" "$a"
printf "6. $d%s$e\n" "$a" # will be yellow
printf "7. $f%s$e\n" "$a" # will be yellow
printf '8. %s%s%s\n' "$d" "$a" "$e" # :(
printf "9. %s%s%s\n" "$f" "$a" "$e" # :(
Can I use %sto expand a color variable and view a color switcher?
Conclusion:
1. foo
2. foo
3. foo
4. foo
5. foo
6. foo
7. foo
8. \e[33mfoo\e[0m
9. \e[33mfoo\e[0m
Note : 6.and 7.really yellow
Edit
printf "10. %b%s%b\n" "$f" "$a" "$e"
... finally! This is the team that does this, thanks to Josh!
source
share