LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 09-13-2006, 02:36 PM   #1
tostay2003
Member
 
Registered: Jun 2006
Posts: 125

Rep: Reputation: 15
simple argument passing


I am trying to pass two arguments to the script, say test.sh

by using ./test.sh abc "xyz"

I want to have the double quotes captured in the variable COLUMN. i.e. the output of this script should be "xyz". How do I do that?


Code:
#!/usr/bin/ksh

if [ $# -lt 2 ]
then
 echo " "
 echo "Invalid number of input parameters. Parameters:"
 exit 1
fi

TABLE=$1
COLUMN=$2

echo ${COLUMN}
 
Old 09-13-2006, 02:46 PM   #2
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 5,950
Blog Entries: 5

Rep: Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755
Make your input to the script:

abc \"xyz\".

The backslashes escape the special meaning of the quotes so they are passed in litterally.
 
Old 09-13-2006, 02:52 PM   #3
tostay2003
Member
 
Registered: Jun 2006
Posts: 125

Original Poster
Rep: Reputation: 15
Is there no way that we can capture it after we pass on the arguments to the script.

Does the $2 dont take quotes at all or is it during the assignment that it gets lost??
 
Old 09-13-2006, 02:52 PM   #4
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,393
Blog Entries: 1

Rep: Reputation: 63
for more complicated inputs, e.g. a"entry"with"several"weird"quotes"""around"
you can use the single quote to pass the entire string litterally:

a"entry"with"several"weird"quotes"""around"
 
Old 09-13-2006, 02:54 PM   #5
tostay2003
Member
 
Registered: Jun 2006
Posts: 125

Original Poster
Rep: Reputation: 15
I want to do it after getting into the script? Is that possible?
 
Old 09-13-2006, 03:03 PM   #6
FreeDoughnut
Member
 
Registered: Jun 2006
Distribution: Slackware 10.2, Debian Testing/Unstable, Ubuntu Breezy Badger, working on LFS
Posts: 228

Rep: Reputation: 30
It isn't because the quotes are done at the shell level. You'd have to guess and add the quotes in the script where you think it would be.
 
Old 09-13-2006, 03:19 PM   #7
tostay2003
Member
 
Registered: Jun 2006
Posts: 125

Original Poster
Rep: Reputation: 15
To guess in script I need to check whether all the characters in the argument are lower case. Could you give me a function that tells, if all the letters in the argument are lower case.

I looked in google to check for that the simple function to check lower case, but its leading to complex codes always.

I want to implement this. Will it work.

Code:
if [check whether $2 is all lower case] 
then
   COLUMN=$2
else
   COLUMN=`\"$2\"`
fi

Last edited by tostay2003; 09-13-2006 at 03:20 PM.
 
Old 09-13-2006, 04:11 PM   #8
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 718

Rep: Reputation: 72
Hi.

I have a partially humorous suggestion. It is true as FreeDoughnut says that the quotes are removed when the shell processes a command -- at least for bash and other Bourne-shell related shells.

The rc shell handles quotes differently. Here's an example of an rc script being called from an interactive rc shell:
Code:
% rc
; cat r1
#!/usr/bin/rc

# @(#) r1       Demonstrate rc shell quoting.

echo "Hello, world."

echo First argument is $1
; ./r1 "a"
"Hello, world."
First argument is "a"
As you can see, the quotes were passed in and echoed.

The rc shell never really caught on, and the only place I saw it used much was at Thinking Machines (TMC) in Boston. However, it seems to be available in many distributions.

Nice to know perhaps, but, as I said, probably not a serious solution -- and, no, I don't know much more about it than that See your friendly man rc page for details (and it is a pretty good man page) ... cheers, makyo
 
  


Reply

Tags
quote, quoting, rc, shell


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
Simple Ooo BASIC Macro problem: "connot coerce argument type..." tredegar Linux - Software 0 08-14-2005 10:00 AM
segfault when passing array[] as argument froboozle Programming 11 06-28-2005 03:06 PM
passing function pointer as argument worldmagic Programming 7 08-04-2004 03:33 PM
How does passing argument to main work Linh Programming 5 06-27-2003 01:08 PM
PHP Script argument passing error... lokee Linux - Software 5 04-24-2003 09:42 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration