*Synopsis*: /bin/sh: expansion of ${1+"$@"} is incorrect CR 7003032 changed on Nov 29 2010 by <User 1-5Q-1267>
=== Field ============ === New Value ============= === Old Value ============= Category shell opensolaris SubCategory korn93 triage-queue ====================== =========================== =========================== *Change Request ID*: 7003032 *Synopsis*: /bin/sh: expansion of ${1+"$@"} is incorrect Product: solaris Category: shell Subcategory: korn93 Type: Defect Subtype: Status: 1-Dispatched Substatus: Priority: 3-Medium Introduced In Release: Introduced In Build: Responsible Engineer: Keywords: opensolaris === *Description* ============================================================ Category shell Sub-Category bourne Description In /bin/sh shell scripts, the expansion of ${1+"$@"} is missing the last argument if that argument is an empty string. According to POSIX:2008 <http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html>, "$@" and ${1+"$@"} should expand to the list of arguments, one by one, not combined together, and not subject to word splitting. The second form is commonly used as a workaround for platforms where the first form does not work, see <http://www.gnu.org/software/autoconf/manual/html_node/Shell-Substitutions.html>. Frequency Always Regression solaris_10 Steps to Reproduce 1) Save this as args.c ========================== args.c ============================== #include <stdio.h> #include <stdlib.h> int main (int argc, char* argv[]) { int i; printf("argc = %d\n",argc); for (i = 0; i < argc; i++) printf("argv[%d] = %s\n",i,argv[i]); exit(0); } ================================================================= 2) Compile it: gcc -o $HOME/bin/args args.c 3) Save this as args-caller.sh ======================== args-caller.sh ========================= #! /bin/sh exec $HOME/bin/args ${1+"$@"} end ================================================================= Make it executable: chmod a+x args-caller.sh 4) Run it with various arguments: $ ./args-caller.sh '' Actual output: argc = 2 argv[0] = /home/bruno/bin/args argv[1] = end Expected output: argc = 3 argv[0] = /home/bruno/bin/args argv[1] = argv[2] = end $ ./args-caller.sh foo '' '' Actual output: argc = 4 argv[0] = /home/bruno/bin/args argv[1] = foo argv[2] = argv[3] = end Expected output: argc = 5 argv[0] = /home/bruno/bin/args argv[1] = foo argv[2] = argv[3] = argv[4] = end Expected Result All arguments should be passed to the program through exec. Actual Result The last argument is not being passed to the program through exec, if it is an empty string. Error Message(s) Test Case 1) Save this as args.c ========================== args.c ============================== #include <stdio.h> #include <stdlib.h> int main (int argc, char* argv[]) { int i; printf("argc = %d\n",argc); for (i = 0; i < argc; i++) printf("argv[%d] = %s\n",i,argv[i]); exit(0); } ================================================================= 2) Compile it: gcc -o $HOME/bin/args args.c 3) Save this as args-caller.sh ======================== args-caller.sh ========================= #! /bin/sh exec $HOME/bin/args ${1+"$@"} end ================================================================= Make it executable: chmod a+x args-caller.sh Workaround Use /bin/bash instead of /bin/sh. Additional configuration information Solaris 11 Express, snv_151a. /bin/sh is a symbolic link to i86/ksh93. *** (#1 of 1): 2010-11-29 03:11:42 GMT+00:00 <User 1-9HOB9N> === *Public Comments* ======================================================== === *Workaround* ============================================================= === *Additional Details* ===================================================== Targeted Release: Commit To Fix In Build: Fixed In Build: Integrated In Build: Verified In Build: See Also: Duplicate of: Hooks: Hook1: Hook2: Hook3: Hook4: Hook5: Hook6: <email address omitted> Program Management: Root Cause: Fix Affects Documentation: No Fix Affects Localization: No === *History* ================================================================ Date Submitted: 2010-11-29 03:11:40 GMT+00:00 Submitted By: <User 1-9HOB9N> Status Changed Date Updated Updated By === *Service Request* ======================================================== Impact: Significant Functionality: Secondary Severity: 3 Product Name: solaris Product Release: solaris_nevada Product Build: snv_151 Operating System: solaris_nevada Hardware: x86 Submitted Date: 2010-11-29 03:11:42 GMT+00:00 === *Multiple Release (MR) Cluster* - 0 ====================================== _______________________________________________ ksh93-integration-discuss mailing list ksh93-integration-discuss@opensolaris.org http://mail.opensolaris.org/mailman/listinfo/ksh93-integration-discuss