|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
In a Bash script I used getopts command to let a user does something regards to the selected options. The question is: How do you find out what is the name of the file that user inserted in the command line like the following:
Quote:
Last edited by bashily; 04-02-2012 at 09:12 PM.. Reason: Better explanation |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
This is from tldp.org - based on your question history I would strongly advise you to read: Advanced Bash-Scripting Guide You can download a pdf from there. It is all free. This is from the getopts page. Among lots of other things it explains getopts use of the : character Code:
while getopts ":abcde:fg" Option # Initial declaration. # a, b, c, d, e, f, and g are the options (flags) expected. # The : after option 'e' shows it will have an argument passed with it. do case $Option in a ) # Do something with variable 'a'. b ) # Do something with variable 'b'. ... e) # Do something with 'e', and also with $OPTARG, # which is the associated argument passed with option 'e'. ... g ) # Do something with variable 'g'. esac done $OPTARG would be the value of -t filename where "t:" exists in the the format string. There is also an example of how to handle trailing arguments that are not options. |
| The Following User Says Thank You to jim mcnamara For This Useful Post: | ||
bashily (04-02-2012) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Thanks so much. it was the greatest help ever! I got what I wanted. The source that you introduced was a fantastic bash scripting source.
Cheers |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Positional Parameters | Straitsfan | UNIX for Dummies Questions & Answers | 1 | 08-24-2009 09:00 PM |
| Setting "default" positional parameters (in bash) | pvdb | Shell Programming and Scripting | 2 | 06-18-2009 02:19 PM |
| Positional parameters | shalu@ibm | UNIX for Dummies Questions & Answers | 2 | 11-22-2007 06:58 AM |
| Positional Parameters | ericelysia | UNIX for Dummies Questions & Answers | 15 | 10-23-2005 03:11 PM |
| Positional Parameters | Shell Programming and Scripting | 2 | 09-26-2003 01:51 PM | |
|
|