Put String/Chars Directly after a Variable?
Hello All,
This might just be a simple yes or no answer to this if anyone could help me out. Is it possible in a Bash Script (or any Shell Script), to put a string right after a variable in an echo statement, without the "string" being considered as part of the variable..? I was trying to simplify using Bold text in a Script... For Example: Code:
#!/bin/bash Any thoughts would be much appreciated! Thanks in Advance, Matt |
Code:
echo -e "${BOLD}Here is Bold Text${BOLDOFF}" |
Wowzerz... LOL Thanks for the QUICK reply!!!
Awesome I'll give that a try... Thanks! Thanks, Matt |
Sweet... Worked Like a charm!!!
Thanks Again, Matt |
The shell reads a variable name as a contiguous string of letters, digits, and the underscore (except that it can't start with a digit). The first character that is illegal in a variable name terminates it.
When you need to combine a variable and a text string like this, the full bracketed form of the variable expansion is the generally accepted way to go about it. Another possibility, however, is to quote each part separately. Code:
echo -e "$BOLD""Here is Bold Text$BOLDOFF" Yet another option, and perhaps the cleanest, is to use printf instead: Code:
printf "$BOLD%s$BOLDOFF\n" "Here is Bold Text" |
Hey David, thanks for the reply...
Cool, thanks for the explanation, and some other options to go with! Thanks Again, Matt |
All times are GMT -5. The time now is 08:55 AM. |