LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to handle character ) in bash shell? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-handle-character-in-bash-shell-877984/)

xombboxer 04-30-2011 05:13 AM

how to handle character ) in bash shell?
 
i have a script where i need to pass an argument "1234:-)"

if i run this as

./shell.sh 1234:-)

it wont work because invalid character.

i need to handle this with expect utility so if i pass it as

./shell.sh "1234:-\)"

no issue in bash but expect does not recognize this.

how to handle this

colucix 04-30-2011 05:22 AM

What about single quotes?
Code:

./shell.sh '1234:-)'
:-)

macemoneta 04-30-2011 05:25 AM

Expect works fine, without escaping:

Code:


$ ./shell.tcl "1234:-)"
1234:-)

$ cat shell.tcl

#!/usr/bin/expect -f
puts "[lindex $argv 0]"


xombboxer 04-30-2011 05:27 AM

I'm trying single quotes ..

it seems both single and double quotes are same. :(

if i pass

./shell.sh '1234:-\)'

from bash i dont get any error.
when it goes to expect it will be 1234:-). this is what i expect, but still im getting message "incorrect password"

colucix 04-30-2011 05:43 AM

Please, try double or single quotes without the escaped parenthesis (as shown in the examples above):
Code:

./shell.sh "1234:-)"
or
Code:

./shell.sh '1234:-)'

grail 04-30-2011 06:15 AM

Or maybe if passing through a bash script to the expect script you need quotes within quotes to keep it all together:
Code:

./shell.sh "'1234:-)'"

xombboxer 04-30-2011 12:17 PM

ok now im trying to replace that character ) with dot . (or some thing else) when required i will replace it back to ). so that my code works. but now how do i replace string in sh script

:( new to linux

MTK358 04-30-2011 01:54 PM

Within single quotes, nothing is substituted, and backslashes are interpreted literally.

Within double quotes, some things still are substituted.

To learn more about BASH scripting, see the "LinuxCommand" tutorial (there's a link in my sig).


All times are GMT -5. The time now is 01:23 PM.