LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-30-2011, 05:13 AM   #1
xombboxer
Member
 
Registered: Apr 2011
Posts: 63

Rep: Reputation: 0
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

Last edited by xombboxer; 04-30-2011 at 05:16 AM.
 
Old 04-30-2011, 05:22 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
What about single quotes?
Code:
./shell.sh '1234:-)'
:-)
 
Old 04-30-2011, 05:25 AM   #3
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Expect works fine, without escaping:

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

$ cat shell.tcl 

#!/usr/bin/expect -f
puts "[lindex $argv 0]"
 
Old 04-30-2011, 05:27 AM   #4
xombboxer
Member
 
Registered: Apr 2011
Posts: 63

Original Poster
Rep: Reputation: 0
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"

Last edited by xombboxer; 04-30-2011 at 05:36 AM.
 
Old 04-30-2011, 05:43 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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:-)'
 
Old 04-30-2011, 06:15 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
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:-)'"
 
Old 04-30-2011, 12:17 PM   #7
xombboxer
Member
 
Registered: Apr 2011
Posts: 63

Original Poster
Rep: Reputation: 0
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
 
Old 04-30-2011, 01:54 PM   #8
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
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).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash: how to handle --options? humbletech99 Programming 4 10-07-2011 07:21 AM
Handle $ character in a string MaryG Linux - Newbie 4 09-11-2009 06:13 AM
Bash scripting: parsing a text file character-by-character Completely Clueless Programming 13 08-12-2009 09:07 AM
Perl File handling issue how to handle ucs 16 character set alix123 Programming 1 10-27-2008 06:51 AM
unzip seems failing to correctly handle chinese character haodongdong Linux - Software 3 04-23-2005 03:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration