LinuxQuestions.org
Register a domain and help support LQ
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, 06: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 06:16 AM.
 
Old 04-30-2011, 06:22 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
What about single quotes?
Code:
./shell.sh '1234:-)'
:-)
 
Old 04-30-2011, 06: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: 332Reputation: 332Reputation: 332Reputation: 332
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, 06: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 06:36 AM.
 
Old 04-30-2011, 06:43 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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, 07:15 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,255

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
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, 01: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, 02:54 PM   #8
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 08:21 AM
Handle $ character in a string MaryG Linux - Newbie 4 09-11-2009 07:13 AM
Bash scripting: parsing a text file character-by-character Completely Clueless Programming 13 08-12-2009 10:07 AM
Perl File handling issue how to handle ucs 16 character set alix123 Programming 1 10-27-2008 07:51 AM
unzip seems failing to correctly handle chinese character haodongdong Linux - Software 3 04-23-2005 04:14 AM


All times are GMT -5. The time now is 03:47 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration