On Thursday, 4 February 2016 03:22:08 UTC+5:30, fpefpe wrote:
>
> I use tcsh via cygwin/windows -- since $path has the ":" removed, it seems
> that the result in $path could be be ambiguous if some of directories could have been in the form ...:/c/program files/foo:... with the ":" removed how does the "scanner" know where the directory starts and ends?
>
csh looks at the $path (lowercase & a csh shell variable) while searching for directories.
$path <=> $PATH transformation is symmetric normally, till we have directories with colons in their names, that's why you would not notice the difference.
Observe the following:
#!/bin/csh
1. set d = "/tmp/a:b"
1. mkdir -p "$d";
2. echo 'echo "Hello, world! from <$0>"' > $d/hello.sh
3. chmod +x "$d/hello.sh"
4. set path = ( $path:q "$d" )
5. echo "PATH=[$PATH]"
6. hello.sh
########
# case-A: path -> PATH
This run successfully in the case of setting the $path first
and cshell autogenerates internally the value of $PATH.
# case-B: PATH -> path
Now change line numbers 4 and 5 to :
setenv PATH "${PATH}:${d}"
echo "$path=[$path]"
Now we reverse the process, and set the $PATH first then let
cshell autogenerate internally the value of $path
You will observe that csh stumbles and converts "a:b" => "a" "b"
that is two directories in place one, since it doesn't know that the
colon (:) in the directory name is a path separator or part of name.
Note, it didn't have any such problem in the path -> PATH conversion.
Hence, (and in the unlikely possibility) that directories "a" and "b"
don't already exist, no preceding dirs contain helo.sh, and "a" or "b"
also don't contain "hello.sh" executable (which can be
anything even a gateway to external intruders) you should see the
re-assuring message that the command hello.sh not found.
This proves that files are searched in the directories specified in $path
(the lowercase path) and not the uppercase $PATH.
To convince yourself, case-B can even written as:
csh -c 'hello.sh' # THIS should give an error that hello.sh command not found
since in this the csh -c '..' inherits the PATH env first, then transforms
that to a lowercase path , and erroneously.
Q.E.D.
-Rakesh