-   Linux - Software (
-   -   simple argument passing (

tostay2003 09-13-2006 03:36 PM

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}

MensaWater 09-13-2006 03:46 PM

Make your input to the script:

abc \"xyz\".

The backslashes escape the special meaning of the quotes so they are passed in litterally.

tostay2003 09-13-2006 03:52 PM

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??

marozsas 09-13-2006 03:52 PM

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:


tostay2003 09-13-2006 03:54 PM

I want to do it after getting into the script? Is that possible?

FreeDoughnut 09-13-2006 04:03 PM

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.

tostay2003 09-13-2006 04:19 PM

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]

makyo 09-13-2006 05:11 PM


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

All times are GMT -5. The time now is 07:32 AM.