string replace in bash script
i want to find something in a string and replace with other string in bash and ksh how do i do that
ex: Code:
mystring="asdf-)" like this Code:
replace(mystring, match, newstring) Code:
mystring="asdf-." |
Hi,
Using bash internals: Code:
mystring=${mystring/)/.} Hope this helps. |
From 'man bash':
Quote:
Code:
mystring="asdf-)" |
yes this is perfect but in my case i have pass this for a sh file from prompt as
Code:
./sh pass="asdf-)" how do i do that... it says bad parameter |
Could you explain your sutuation better? And where exactly do you want to do substitution?
|
ok
i had enough trouble with with expect and special character ')'. i will replace ')' with say 'n' while passing the parameter and in the expect utility i will replace back 'n' with ')' my requirement now is how do i replace 'n' with ')' withing expect utility. Code:
${mystring/)/.} please help me :( |
What is this "expect" you keep talking abut?
|
Quote:
|
hi MTK358
its an utility used to automate things like automatic password entry etc . i too dont know much about it. i think its sort of TCL |
@xombboxer: You talk about two scripts, input from the prompt and expect. Do you mind posting what you have and telling which line(s) are not working?
|
first im calling
Code:
./main.sh pass="p:-\)10" from main.sh again im calling one more sh file Code:
../_exp.sh $PASS Code:
"p:-\)10" Code:
#!/usr/bin/expect -f the problem is because of the special character ')'. it is correctly interpreted in main.sh. But when it goes to second shell file which is to handle expect utility, it does not recognize '\' as escape character. it treats "p:-\)10" as 7 character string but actually my password is 6 character string "p:-)10". |
Hi,
Quote:
Wouldn't ./main.sh "p:-\)10" (or ./main.sh 'p:-)10') be easier? Inside the script you can do: PASS="$1" If you put single quotes around the input instead of double quotes, you do not need to escape the ) when starting the main script. Quote:
Code:
#/bin/bash Hope this helps. |
All times are GMT -5. The time now is 08:39 PM. |