in reply to Re: sudo ignoring string entry after first space encountered
in thread sudo ignoring string entry after first space encountered

Hi, I'm not sure an apples to apples example is possible in print. I have sudu set up as an alias (alias sudu='sudo -H -u prodaccount SudoENV.ksh where SuoENV.ksh is a bash shell script that references the prodaccount environment variables. Actual command line example; sudu optim_table.pl -i ab_in_keys_201504 -ic NZMDSODS -n 1000 -o work_cal_123 -oc NZMDSODS -u clough -w "track_seq in ('Z010201503052014871','Z0102015030520148710')" .pl snippets

GetOptions ("i=s" => \$input_tbl, "ic=s" => \$input_con_str, ## defaults to +"nzmdsods" "o=s" => \$output_tbl, ## defaults to +"${input_tbl}" "oc=s" => \$output_con_str, ## defaults to +"nzmdsods" "u=s" => \$user, "k=s" => \$key, ## defaults to +"rowid" "w=s" => \$where_condition, ## defaults to +"1=1" "n=i" => \$rec_count, ## defaults to +1000 "cfg=s" => \$config_file, ## defaults to +same name as report file; if specified, overrides pii class mapping "ld=s" => \$log_dir ## defaults to +"/Projects/OPScripts/MDS/logs" ); ..... print "CED WHERE CONDITION $where_condition\n"; $where_condition = "1=1" if (!$where_condition); $where_clause = "where $where_condition"; print "CED WHERE CLAUSE $where_clause\n";
result: CED WHERE CONDITION track_seq CED WHERE CLAUSE track_seq expected: CED WHERE CONDITION track_seq in ('Z010201503052014','Z010201503052014') CED WHERE CONDITION track_seq in ('Z010201503052014','Z010201503052014') This may not be a perl issue per se and more of a shell issue. I'm hoping the symptoms described will foster some thoughts/tricks on how to rectify the quirk.

Replies are listed 'Best First'.
Re^3: sudo ignoring string entry after first space encountered ("$@")
by tye (Sage) on Apr 15, 2015 at 03:08 UTC
    where SuoENV.ksh is a bash shell script

    So are you using $* in your script where you should be using "$@" ?

    $ cat wrapper #!/bin/bash perl -le'print for @ARGV' $* perl -le'print for @ARGV' "$@" $ ./wrapper foo "a b c" foo a b c foo a b c

    - tye        

      Thank-you much for your response(s). In theory this should address the symptom and had been recommened from other quarters. However it was to no avail. I changed the script to read the where clause from a file, rather than command line entry, which gets me over the hump for the time being. I'm still in persuit of a pure solution as I suspect this will crop up again.

        Then perhaps you are parsing the arguments (in your shell script) and using things like $1 instead of "$1"?

        - tye        

        If passing the string via a file proves to be the only workable option for you, you could write a script that saves the string to a file, then runs the sudo command. This would simplify the users' interactions with your current script.