Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I would have a question on the command "getopts", if I want to perform a command with an unlimited argument
such as:
foo -cd {filename1 filename2 filename3.....}
in the shell script:
while getopts cd: opt
do
case "$opt"
d) `ls $OPTARG`;;
c) do something
done
As a result, only the first file name can be read.
how can I handle the shell script for this command..............I have find a lot of site and book, they also haven't mention that.........

That's because the cd: means that you have -c which doesn't take any options and -d which takes one. Saying -cd is the same as saying -c -d
If you tell me what you're trying to do I'll try to work it out, but the only things I know about getopt is the manpage and the examples in /usr/share/doc/util-linux/examples

As previously stated, you have the syntax incorrect, but it is not quite clear what exactly you are trying to do so I can't really give you any pointers.
Sean

For example, If I would like to write a command that list all the directory usage in the given directory
and owner in one or more directories, and *should use the "getopts" command. If I provide the option "-c" the
command will first clear the screen and all the file to a specific file.
the command is such like this:Usage: foo [-c] [-d] {directory1 directory2 ....}
-c: clear screen
-d: show all directory size usage in the given directory
The restriction is that I can't put quotation to the directory that "directory1 directory2...",
as in the man page mention that.....the "directory1, directory2...." will be treated as [argument list...]
Please help me, thank a lot!

Sorry.......the previous message has somethings typed wrong.This is the amended version.
For example, If I would like to write a command that list all the directory usage and related owner in one or more given directories, and *should use the "getopts" command. If I provide the option "-c" the command will first clear the screen and then list all the information mention above to the screen.
the command is such like this:Usage: foo [-c] [-d] {directory1 directory2 ....}
-c: clear screen
-d: show all directory size usage in the given directory
The restriction is that I can't put quotation to the directory that "directory1 directory2...",
as in the man page mention that.....the "directory1, directory2...." will be treated as [argument list...] if not have any quotation(single or double) or not list in a single variable by using comma.
Please help me, thank a lot!

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |