How to remove a certain character from a variable
Hi
I want to remove single quote from a variable. eg: Suppose I have a variable VAR='TEST' (including single quotes) How can I remove single quotes and make it TEST. Thanks in advance for your valuable help... |
Code:
[mherring@mystical ~]$ var="'test'" |
Or using (a bit more cryptic) parameter substitution:
Code:
$ echo ${var//\'/} |
Here's another, just so you have a variety of methods to choose from. Probably the example above by colucix is the most efficient, since it is wholly done by the shell (no external tools), but this one here uses `tr` in the same manner as Pixellany's code uses `sed`; `tr` is a little faster than `sed` though, so if you had to do a million of this, you might notice `tr` saves a little time:
Code:
echo "'test'" | tr -d \' |
Thanks....
|
Don't forget to mark as SOLVED when you have your solution.
|
All times are GMT -5. The time now is 08:45 PM. |