Sunday, 15 September 2013

Search and Replace in a variable string with Shell scripts

Search and Replace in a variable string with Shell scripts

I am in dilemma about how could I search and replace a particular
character in a variable of a shell script.
e.g. I have a condition where I need to pass '~' to the java program but I
should pass it as '/~' to avoid it being intercepted as $HOME. I have a
shell variable e.g. $1 = '.-~' and I am passing it directly to the Java
program as an argument. So how could I modify this variable in such a way
that it searches for '~' and if it finds then changes $1 = '.-/~' so as to
avoid the error in Java program.

No comments:

Post a Comment