Reputation: 19294
I have a simple bash script that looks like this:
RED=$(tput setaf 1)
echo "$REDERROR - ..."
and I want it to print ERROR
in red.
If i change my code to this:
RED=$(tput setaf 1)
echo "$RED ERROR - ..."
it prints ERROR
in red but with a leading space.
So how can I eliminate that leading space and still reference my variable $RED
before it?
Upvotes: 1
Views: 121
Reputation: 60107
Use curly braces:
echo "${RED}ERROR - ..."
String concatenation also works:
echo "$RED""ERROR - ..."
(Quotes around $RED
aren't technically needed given its particular contents (no spaces or other field seperators) and therefore echo $RED"ERROR - ..."
will give the same result.)
Upvotes: 5