This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: [SOLVED] Re: tcsh path conversion messed up?


On November 07, 2017 11:08 PM Will Parsons wrote:
>Lemke, Michael  ST/HZA-ZIC2 wrote:
>> On Tuesday, November 07, 2017 7:12 AM Brian Inglis wrote:
>>>On 2017-11-06 14:59, Will Parsons wrote:
>>>> Will Parsons wrote:
>>>>> I asked about what I thought was a shell scripting problem:
>>>>>    PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/c/Windows/system32:/c/Windows:/c/Windows/system32/wbem:/c/ProgramData/Oracle/Java/javapath:/c/Program:Files/Common:Files/Microsoft:Shared/Windows:Live:/c/Program:Files:(x86)/Common:Files/Microsoft:Shared/Windows:Live:/c/Program:Files/Dell/DW:WLAN:Card:/c/Program:Files:(x86)/Intel/iCLS:Client:/c/Program:Files/Intel/iCLS:Client:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Program:Files/WIDCOMM/Bluetooth:Software:/c/Program:Files/WIDCOMM/Bluetooth:Software/syswow64:/c/Program:Files:(x86)/Windows:Live/Shared:/c/Program:Files:(x86)/Bazaar:/c/Program:Files:(x86)/QuickTime/QTSystem:/c/cygwin/home/william/bin:/c/ezwinports/bin:/c/Program:Files:(x86)/PuTTY:/usr/lib/lapack
>>>>>
>>>>> This doesn't look right, and would explain the strange shell output I
>>>>> reported.  (The value of PATH under bash looks normal.)  Did the installation
>>>>> of tcsh somehow get corrupted?  I don't remember a particularly recent update
>>>>> to tcsh.
>>
>> How are you setting path? Do you have anything in your .cshrc/.login file? Most
>> likely, you are doing it wrong. 
>>
>>>> Another bit of info - I just noticed that the value of the (t)csh shell
>>>> variable 'path' is:
>>>
>>>In csh, "PATH" is a standard Unix environment variable whose value is a colon
>>>separated directory list, and "path" is a shell wordlist kept synchonized with
>>>"PATH".
>>>To list the wordlist entries with embedded spaces in csh, quote the variable
>>>name with the :q modifier in a foreach loop wordlist, and you get the desired
>>>result as easily as in your sh script [trimmed and ...s redacted]:
>>>
>>>.......% foreach p ( $path:q )
>>>foreach?	echo $p
>>>foreach? end
>>
>> And that is also key for setting path:
>>
>> set path = ( ... $path:q )
>>
>> I had this bug ($path instead of $path:q) for 20 years in my init files.
>
>Bingo!  I had this line in my ~/.cshrc:
>
>  set path = ( /usr/local/bin /usr/bin /bin /usr/sbin $path )
>
>Changing $path to $path.q solved the problem.

For the record, it is $path:q not $path.q

>
>(I am still somewhat puzzled, though - the original PATH that I quoted in my
>original query did have spaces, so what changed?)

Nothing. csh treats PATH differently. I am not sure about all the details and
how/if PATH and path are synchronized but in csh you define the path with "path",
which is an array. "PATH" is only a string that gets parsed into individual
elements by using : as the separator. Not so "path". You set its elements as

set path = ( path1 path2 ... )

where the space is the separator. So how to add an element with a space? You 
add quotes:

set path = ( "/cygdrive/c/program files" /usr/bin )

But that won't work in a simple replacement. In

  set path = ( /usr/local/bin $path )

$path expands into the space separated words producing what you saw. Think of
it like you typed it yourself (note that path does not contain any quotes). 
So you'd think to do this:

  set path = ( /usr/local/bin "$path" )

Won't work either. It creates 2 entries with the last one being everything
in path as a single entry. So you need to quote it differently or write a loop.
Use the :q modifier to make $path expand as array elements. This is what :q is for.
In Unix you most likely don't notice the difference as Unix directories usually
have no spaces. But it is exactly the same.

>
>At any rate, the problem seems to be solved, so thank you very much.

You might even find that more windows commands are now available (e.g. java), which
got installed into Program Files and added to PATH.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]