- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: User input for command flags
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2008 06:53 AM
тАО02-12-2008 06:53 AM
For example if the command is:
What can I do to get the user to input the date he/she wants and keep it in the above format (MM/DD/YY) and also get prompted to enter the group name?
Any help will be appreciated very very much!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2008 07:13 AM
тАО02-12-2008 07:13 AM
Re: User input for command flags
Since your example is the standard switch-plus-argument format, you should consider using 'getopts()' to parse the switches and arguments.
http://docs.hp.com/en/B3921-60631/getopts.1.html
You are going to have to examine and verify the argument for "correctness" thereafter. For example, a valid date in the format shown would have a one or two digit month in the range 1-12. Similarly, you will have to define what constitutes a valid argument for '-q'.
Using regular expressions with 'grep' or 'awk' will help in the date validation, although you could simply 'cut' the field into pieces and make appropriate verifications to do that.
Regards!
...JRF...
- Tags:
- getopt/getopts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2008 08:09 AM
тАО02-12-2008 08:09 AM
Re: User input for command flags
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2008 09:07 AM
тАО02-12-2008 09:07 AM
Solution#!/usr/bin/perl
use strict;
use diagnostics;
use warnings;
my $group;
print "Please Enter Date in the format MM/DD/YY: ";
my $date=
chomp($date);
while() {
if($date=~/[0-1][0-9]\/[0-3][0-9]\/\d\d/) {
print "Please Enter Group Name: ";
$group=
exit(0);
}else{
print "Invalid Date\n";
print "Please Enter Date in the format MM/DD/YY: ";
$date=
}
}
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2008 09:46 AM
тАО02-12-2008 09:46 AM
Re: User input for command flags
This should get you started:
# cat .example
#!/usr/bin/sh
while getopts t:q: THINGS
do
case ${THINGS} in
t)
OPT_T=1
VAL_T=${OPTARG}
;;
q)
OPT_Q=1
VAL_Q=${OPTARG}
;;
?)
printf "Usage: %s: [-t date] [-q value]\n" $0
exit 2;;
esac
done
if [ ! -z "${OPT_T}" ] ; then
printf "Option -t with %s\n" ${VAL_T}
fi
if [ ! -z "${OPT_Q}" ] ; then
printf "Option -q with %s\n" ${VAL_Q}
fi
shift $(( $OPTIND -1 ))
if [ $# = 0 ]; then
print "No arguments remain"
else
printf "Arguments remaining: %s\n" "$@"
fi
exit 0
# ./example -q group=mine -t 02/12/2008 myfile
Option -t with 02/12/2008
Option -q with group=mine
Arguments remaining: myfile
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2008 02:41 PM
тАО02-13-2008 02:41 PM