Hi Regina,
The problem is caused by the eval shell statement:
eval "exec ctperl -S $0 $*"
When the shell runs your shell script, the quotation marks have preserved
the space in the "John Smith" command-line argument, but the quotation marks
are stripped away by the time the script "sees" that argument. So, that
part of the $* argument list expands to John Smith (quoteless). In the
expansion it is a single command line argument, but you are leaving the
space exposed on that eval exec... command line. This splits the John Smith
into two args for the ctperl script.
Is the shell wrapper necessary around your ctperl script?
Chris
On Wed, Jun 17, 2009 at 9:48 AM, Shlomi Fish <shlomif@...> wrote:
> On Wednesday 17 June 2009 19:38:04 rmiller571957 wrote:
> > Thanks very much for the advice on not using $ARGV's directly.
> > I will change my code to match.
> >
>
> It's not $ARGV - it's @ARGV. @ARGV is the entire array. $ARGV[$index] is an
> individual element of it. There's also $ARGV in Perl which is a different
> thing.
>
> > But I'm not sure how your example of system("echo"...) applies to the
> > embedded blanks in a parameter issue.
> >
> > What I would like is for the user to be able to use one word, or two
> words,
> > or three words (or even more, I guess) for the 2nd parameter. That is:
> > "Smith" or "Mary Smith" or "Mary Ann Smith".
> > And I would like all of these to be picked up as just the single
> parameter,
> > regardless of how many embedded spaces there are between the quotes.
> >
>
> If you do, for example:
>
> {{{
> system("ls", "-l", "Hello there/");
> }}}
>
> Then ls will display the files under the "Hello there" directory with a
> space
> in the path. You see - the list form of system treats each of the
> components
> of the list as a single command-line argument, even if it contains spaces.
>
> So this would be equivalent to doing the following commands in the shell:
>
> {{{
> ls -l "Hello there/"
> ls -l 'Hello there/'
> ls -l Hello\ there/
> }}}
>
> Regards,
>
> Shlomi Fish
>
> > Thanks again for any help.
> > Regina
> >
> > --- In perl-beginner@yahoogroups.com, Shlomi Fish <shlomif@...> wrote:
> > > On Wednesday 17 June 2009 18:29:40 Regina Miller wrote:
> > > > Hi,
> > >
> > > Hi!
> > >
> > > First of all, you shouldn't use $ARGV[0] , $ARGV[1], etc. directly. Do:
> > >
> > > {{{
> > > my ($first_name, $last_name, $address) = @ARGV;
> > > }}}
> > >
> > > Which is a much more robust idea.
> > >
> > > Secondly, look at the list form of system:
> > >
> > > {{{
> > > system("echo", "One two", "three four--five");
> > > }}}
> > >
> > > Hope it helps.
> > >
> > > Regards,
> > >
> > > Shlomi Fish
> > >
> > > > My script to add a new user is below, written on solaris 10.
> > > >
> > > >
> > > >
> > > > Running it using either of these two ways (one with double quotes
> > > > around the second parameter and one with single quotes):
> > > >
> > > > ./adduser.sh TestAcct "John Smith" Law
> > > >
> > > > ./adduser.sh TestAcct 'John Smith' Law
> > > >
> > > > My script thinks I have entered four parameters.
> > > >
> > > >
> > > >
> > > > But when I run it using the following (with no embedded spaces):
> > > >
> > > > ./adduser.sh TestAcct JohnSmith Law
> > > >
> > > > It then thinks I have entered three parameters.
> > > >
> > > >
> > > >
> > > > How do I get a parameter that has embedded spaces to register as just
> > > > one parameter??
> > > >
> > > >
> > > >
> > > > Thanks for any help,
> > > >
> > > > Regina
> > > >
> > > >
> > > >
> > > > Regina Miller
> > > >
> > > > Lead Analyst, Grays Harbor County
> > > >
> > > > (360) 249-4144 ext 457
> > > >
> > > > rmiller@...
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > MY SCRIPT
> > > >
> > > >
> > > >
> > > > eval "exec ctperl -S $0 $*"
> > > >
> > > > if $running_via_sh;
> > > >
> > > > #$Id: adduser.sh,v 302.4 1995/07/21 16:29:18 nick Exp $
> > > >
> > > > #require 'ctree.pl';
> > > >
> > > >
> #######################################################################
> > > ># ########
> > > >
> > > > # %perl
> > > >
> > > > # %width 80
> > > >
> > > > # %title Add a New User
> > > >
> > > > # %name adduser.sh
> > > >
> > > >
> > > >
> > > > use strict;
> > > >
> > > > use warnings;
> > > >
> > > >
> > > >
> > > > die 'Usage: adduser username "full name" group. i.e. adduser
> testacct
> > > > "John Smith" Law'
> > > >
> > > > unless @ARGV == 3;
> > > >
> > > >
> > > >
> > > > unless (system "useradd -g $ARGV[2] -d /home/$ARGV[0] -m -s
> > > > /usr/bin/ksh -c $ARGV[1] $ARGV[0]")
> > > >
> > > > {
> > > >
> > > > system "passwd $ARGV[0]";
> > > >
> > > > exit;
> > > >
> > > > }
> > > >
> > > > print "Error. User can not be added\n";
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > [Non-text portions of this message have been removed]
>
> --
> -----------------------------------------------------------------
> Shlomi Fish http://www.shlomifish.org/
> Interview with Ben Collins-Sussman - http://xrl.us/bjn8s
>
> God gave us two eyes and ten fingers so we will type five times as much as
> we
> read.
>
>
> ------------------------------------
>
> Unsubscribing info is here:
> http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo! Groups Links
>
>
>
>
[Non-text portions of this message have been removed]