bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Issue with Getopts


From: Greg Wooledge
Subject: Re: Issue with Getopts
Date: Mon, 15 Nov 2010 08:32:11 -0500
User-agent: Mutt/1.4.2.3i

On Mon, Nov 15, 2010 at 12:41:19PM +0530, Ajay Jain wrote:
> I use 'getopts' in my shell script. If I run script normally, it works
> fine. However, the moment I run the script in the current shell (ie .
> <script.sh>), it fails returning error. Basically it is not able to
> parse the arguments. Any reason, why?

If you type

  . ./script.sh

then the arguments you pass to script.sh are whatever your "$@"
(positional parameter vector) just happens to have at the moment.

imadev:~$ . ./bin/args
1 args: <something ;`ls /`>
imadev:~$ echo "$@"
something ;`ls /`

And no, don't ask why I have that in my interactive shell's "$@",
because I truly don't remember.  I blame IRC.

If you type some actual ARGUMENTS after the script name, then those are
used as "$@".

imadev:~$ . ./bin/args one two
2 args: <one> <two>

So, you need to invoke the script properly.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]