Computing.Net > Forums > Linux > Shell Script Question

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Shell Script Question

Reply to Message Icon

Name: Andrew
Date: October 14, 2002 at 20:35:02 Pacific
OS: Win 2k
CPU/Ram: PIII 256mb
Comment:

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.........




Sponsored Link
Ads by Google

Response Number 1
Name: Richard
Date: October 15, 2002 at 02:42:36 Pacific
Reply:

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


-1

Response Number 2
Name: Sean Miller
Date: October 15, 2002 at 03:14:34 Pacific
Reply:

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



-1

Response Number 3
Name: Andrew
Date: October 15, 2002 at 10:10:08 Pacific
Reply:

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!


0

Response Number 4
Name: Andrew
Date: October 15, 2002 at 10:15:04 Pacific
Reply:

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!


-1

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: Shell Script Question

begginner shell script help ASAP! www.computing.net/answers/linux/begginner-shell-script-help-asap/18683.html

Linux shell script www.computing.net/answers/linux/linux-shell-script/11120.html

Easy shell script question? www.computing.net/answers/linux/easy-shell-script-question/19758.html