I am stuck on testing for Optional parameters in a c-shell script. this what I have so far
#!/bin/cshif($1 == "") then
echo "This shell script compresses files with a specific extension"
echo "Call syntax: minimize <suffix_name> <zipprog> <Size>
"
echo "Example: minimize doc"
exit
endifif ($2 == "") then
set $3 = `compress`
endifecho $1
echo $2
echo $3
echo $4
foreach file(`\ls`)
#if ($file =~ *.$1) then
if (-f $file && $file =~ *.$1) then
set size = (`wc -c $file`)
if ($size[1] < $4 ) then
$3 $file
endif
endif
endthe second If statement is failing with a missing File name error. Not sure what I am Missing since the first if statement works correctly. If I comment out the 2nd if, the script will work as it should with all the parameters filled in.
the object is to supply a directory, a list of file types, and the script will compress the those files. the optional part is to let the script know the size of the files to compress and which compression program to use. it should default to compress,minimize -s 500 -p gzip /etc/host txt
thanks
The reason you are getting a missing filename error is because with command line substitution you are trying to set the contents of the compress command to $3: set $3 = 'compress`
Instead, build the command as a string and then execute it like in this test stub:
#!/bin/csh foreach file(`ls`) set command='ls -l '$file $command end
# end test stubSometimes, if the command string is complicated is complicated, instead of this:
$command
it must be eval'ed:
eval $command
| « Making a batch file to ch... | Multiple program run and ... » |