Name: Anonymous 2012-01-31 17:37
Hey guys, I'm writing a C-shell command and I want to give the user options when running the command for example I'm trying to make a command that compresses all of the files in a directory with a user defined extension (.txt .pdf etc...) that's over a specific size and using either a default program to compress the file.
This is what I have so far
#!/bin/csh
if ($2 == "") then
#Check if the second argument is empty
echo "This shell script compress files with a specific extension"
echo -n "Call syntax: minimize [-s size] [-p prog] <directory> "
echo "<ext_list>"
echo -n "Where what is between [and] is optional whereas what is between "
echo "<and> is not."
echo "Example: minimize -s 10000 -p gzip ./ ps pdf"
echo -n "All files in the current directory over 10000 bytes with the "
echo "extension ps or pdf will be compressed using gzip"
exit
endif
if (-d $1) then
#Check if the frist argument is a directoy
echo "This is a directory"
echo "files will be compressed"
foreach file (`$1`)
#Look at each file in the user specified directory
if ($file =~ *.$2) then
#Compress all files in the specified directory that match the extensions in the second argument specified by the user
compress $file
echo $file "has been compressed"
endif
end
else
echo $1 "is not an acceptable directory"
exit
endif
---------------------------------------------------
I just fundamentally don't understand how to set up options, any advice?
This is what I have so far
#!/bin/csh
if ($2 == "") then
#Check if the second argument is empty
echo "This shell script compress files with a specific extension"
echo -n "Call syntax: minimize [-s size] [-p prog] <directory> "
echo "<ext_list>"
echo -n "Where what is between [and] is optional whereas what is between "
echo "<and> is not."
echo "Example: minimize -s 10000 -p gzip ./ ps pdf"
echo -n "All files in the current directory over 10000 bytes with the "
echo "extension ps or pdf will be compressed using gzip"
exit
endif
if (-d $1) then
#Check if the frist argument is a directoy
echo "This is a directory"
echo "files will be compressed"
foreach file (`$1`)
#Look at each file in the user specified directory
if ($file =~ *.$2) then
#Compress all files in the specified directory that match the extensions in the second argument specified by the user
compress $file
echo $file "has been compressed"
endif
end
else
echo $1 "is not an acceptable directory"
exit
endif
---------------------------------------------------
I just fundamentally don't understand how to set up options, any advice?