Possible syntax failures in /etc/profile

Bruce Jerrick bmj001@gmail.com
Thu Feb 15 17:25:35 GMT 2024


(Forgive me if this is a duplicate -- my first attempt seems to have
slipped into a black hole.)

In the snippet below from /etc/defaults/etc/profile (base-files-4.3-3),
the '[]' tests can fail with the syntax error:

  -bash: [: =: unary operator expected

if CYGWIN_USEWINPATH or CYGWIN_NOWINPATH are set to a null (empty)
string.  (There's nothing on the left side of the '='.)
Any indication of an error seems to slip into a black hole somewhere.

The fix would be either to surround their expansions in double-quotes,
or use ':-' in place of '-' in their expansions (i.e., do the
substitition if unset or null, not just unset).  (Per 'man sh',
"Parameter Expansion".)

The code is as follows (expansions marked with '*'):

   # setting CYGWIN_USEWINPATH non-empty in the system variables
   # assumes that you've already set up PATH so that Cygwin works
   # correctly -- no further alteration is done
*  if [ ${CYGWIN_USEWINPATH-pathprepend} = "pathprepend" ] ; then
     # setting CYGWIN_NOWINPATH non-empty in the system variables
     # prevents use of the existing PATH and a clean PATH just for
     # Cygwin is set up -- you need to add any extra path components
     # you need in your personal startup files
*    if [ ${CYGWIN_NOWINPATH-addwinpath} = "addwinpath" ] ; then
         PATH="/usr/local/bin:/usr/bin${PATH:+:${PATH}}"
     else
         PATH="/usr/local/bin:/usr/bin"
     fi
   fi

P.S.: When testing, note that the code is effectively execute-once,
due to the PROFILEREAD variable.



More information about the Cygwin mailing list