I was trying to deciper someone else code. I'm just learning tcl. I was a litte confused about the $argv[1]. I was thinking it would be only a certain value in argv..but if say someone give the switch -cell and -path_to_ezqb is it right to have the second one $argv[1]???
while ($#argv > 0)
set arg=$argv[1]
shift argv
switch ($arg)
case "-cell":
set cell=$argv[1]
if ( !($cell == "bus" || $cell == "core")) then
echo "\n******Valid cell names are core or bus******"
goto help
else
echo "cell = ${cell}"
endif
breaksw;
case "-path_to_ezqb":
set path_to_ezqb=$argv[1]
This code does not look like Tcl. It looks more like Perl to me.
Anyway, the operation shift removes first entry from array, something like:
A[1]=A[2]; A[2]=A[3]; ...
so the code indeed can iterate over whole array, since every element end up as argv[1] at some point. Sh and perl programmers often do it this way.
This is probably a csh fragment. Here it is inserted into a csh script:
#!/usr/bin/env tcsh
# @(#) s1 Demonstrate feature.
# Infrastructure details, environment, commands for forum posts.
# Uncomment setenv command to run script as external user.
# setenv PATH "/usr/local/bin:/usr/bin:/bin"
echo
setenv LC_ALL C ; setenv LANG C
echo "Environment: LC_ALL = $LC_ALL, LANG = $LANG"
echo "(Versions displayed with local utility version)"
sh -c "version >/dev/null 2>&1 && version '=o' tcsh"
echo
while ($#argv > 0)
set arg=$argv[1]
shift argv
switch ($arg)
case "-cell":
set cell=$argv[1]
if ( !($cell == "bus" || $cell == "core")) then
echo "\n******Valid cell names are core or bus******"
goto help
else
echo "cell = ${cell}"
endif
breaksw;
case "-path_to_ezqb":
set path_to_ezqb=$argv[1]
endsw
end
exit 0
producing:
% ./s1 -cell x
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility version)
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution : Debian GNU/Linux 5.0.7 (lenny)
tcsh 6.14.00
******Valid cell names are core or bus******
help: label not found.