Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Software
User Name
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.


  Search this Thread
Old 09-13-2006, 02:36 PM   #1
Registered: Jun 2006
Posts: 126

Rep: Reputation: 15
simple argument passing

I am trying to pass two arguments to the script, say

by using ./ 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?


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


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

Rep: Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668
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
Registered: Jun 2006
Posts: 126

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
Senior Member
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,474
Blog Entries: 1

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

Old 09-13-2006, 02:54 PM   #5
Registered: Jun 2006
Posts: 126

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
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
Registered: Jun 2006
Posts: 126

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.

if [check whether $2 is all lower case] 

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

Rep: Reputation: 75

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:
% rc
; cat r1

# @(#) 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


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 > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:59 PM.

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