<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: User input for command flags in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/user-input-for-command-flags/m-p/4143807#M93422</link>
    <description>This is something that i put together in perl, hope this helps.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use diagnostics;&lt;BR /&gt;use warnings;&lt;BR /&gt; &lt;BR /&gt;my $group;&lt;BR /&gt;print "Please Enter Date in the format MM/DD/YY: ";&lt;BR /&gt;my $date=&lt;STDIN&gt;;&lt;BR /&gt;chomp($date);&lt;BR /&gt;while() {&lt;BR /&gt;if($date=~/[0-1][0-9]\/[0-3][0-9]\/\d\d/) {&lt;BR /&gt;   print "Please Enter Group Name: ";&lt;BR /&gt;   $group=&lt;STDIN&gt;;&lt;BR /&gt;   exit(0);&lt;BR /&gt;}else{&lt;BR /&gt;    print "Invalid Date\n";&lt;BR /&gt;    print "Please Enter Date in the format MM/DD/YY: ";&lt;BR /&gt;    $date=&lt;STDIN&gt;;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;/STDIN&gt;&lt;/STDIN&gt;&lt;/STDIN&gt;</description>
    <pubDate>Tue, 12 Feb 2008 17:07:51 GMT</pubDate>
    <dc:creator>David Bellamy</dc:creator>
    <dc:date>2008-02-12T17:07:51Z</dc:date>
    <item>
      <title>User input for command flags</title>
      <link>https://community.hpe.com/t5/operating-system-linux/user-input-for-command-flags/m-p/4143804#M93419</link>
      <description>I am trying to set up a shell script that will prompt a user to enter a date and a second parameter.&lt;BR /&gt;&lt;BR /&gt;For example if the command is:&lt;BR /&gt;&lt;BR /&gt;&lt;COMMAND&gt; -t '02/12/08' -q 'group=MY_GROUP'&lt;BR /&gt;&lt;BR /&gt;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?&lt;BR /&gt;&lt;BR /&gt;Any help will be appreciated very very much!&lt;BR /&gt;&lt;BR /&gt;&lt;/COMMAND&gt;</description>
      <pubDate>Tue, 12 Feb 2008 14:53:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/user-input-for-command-flags/m-p/4143804#M93419</guid>
      <dc:creator>Vic S. Kelan</dc:creator>
      <dc:date>2008-02-12T14:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: User input for command flags</title>
      <link>https://community.hpe.com/t5/operating-system-linux/user-input-for-command-flags/m-p/4143805#M93420</link>
      <description>Hi Vic:&lt;BR /&gt;&lt;BR /&gt;Since your example is the standard switch-plus-argument format, you should consider using 'getopts()' to parse the switches and arguments.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://docs.hp.com/en/B3921-60631/getopts.1.html" target="_blank"&gt;http://docs.hp.com/en/B3921-60631/getopts.1.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;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'.&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 12 Feb 2008 15:13:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/user-input-for-command-flags/m-p/4143805#M93420</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-02-12T15:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: User input for command flags</title>
      <link>https://community.hpe.com/t5/operating-system-linux/user-input-for-command-flags/m-p/4143806#M93421</link>
      <description>Thanks JRF, I am not very familiar with the getopts and could not figure out how to use it from the man, actually very rusty with scripts. Do you have an example that could lead me on my way and I take it from there?&lt;BR /&gt;&lt;BR /&gt;Thanks!</description>
      <pubDate>Tue, 12 Feb 2008 16:09:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/user-input-for-command-flags/m-p/4143806#M93421</guid>
      <dc:creator>Vic S. Kelan</dc:creator>
      <dc:date>2008-02-12T16:09:26Z</dc:date>
    </item>
    <item>
      <title>Re: User input for command flags</title>
      <link>https://community.hpe.com/t5/operating-system-linux/user-input-for-command-flags/m-p/4143807#M93422</link>
      <description>This is something that i put together in perl, hope this helps.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use diagnostics;&lt;BR /&gt;use warnings;&lt;BR /&gt; &lt;BR /&gt;my $group;&lt;BR /&gt;print "Please Enter Date in the format MM/DD/YY: ";&lt;BR /&gt;my $date=&lt;STDIN&gt;;&lt;BR /&gt;chomp($date);&lt;BR /&gt;while() {&lt;BR /&gt;if($date=~/[0-1][0-9]\/[0-3][0-9]\/\d\d/) {&lt;BR /&gt;   print "Please Enter Group Name: ";&lt;BR /&gt;   $group=&lt;STDIN&gt;;&lt;BR /&gt;   exit(0);&lt;BR /&gt;}else{&lt;BR /&gt;    print "Invalid Date\n";&lt;BR /&gt;    print "Please Enter Date in the format MM/DD/YY: ";&lt;BR /&gt;    $date=&lt;STDIN&gt;;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;/STDIN&gt;&lt;/STDIN&gt;&lt;/STDIN&gt;</description>
      <pubDate>Tue, 12 Feb 2008 17:07:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/user-input-for-command-flags/m-p/4143807#M93422</guid>
      <dc:creator>David Bellamy</dc:creator>
      <dc:date>2008-02-12T17:07:51Z</dc:date>
    </item>
    <item>
      <title>Re: User input for command flags</title>
      <link>https://community.hpe.com/t5/operating-system-linux/user-input-for-command-flags/m-p/4143808#M93423</link>
      <description>&lt;!--!*#--&gt;Hi (again) Vic:&lt;BR /&gt;&lt;BR /&gt;This should get you started:&lt;BR /&gt;&lt;BR /&gt;# cat .example&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;while getopts t:q: THINGS&lt;BR /&gt;do&lt;BR /&gt;    case ${THINGS} in&lt;BR /&gt;    t)&lt;BR /&gt;        OPT_T=1&lt;BR /&gt;        VAL_T=${OPTARG}&lt;BR /&gt;        ;;&lt;BR /&gt;    q)&lt;BR /&gt;        OPT_Q=1&lt;BR /&gt;        VAL_Q=${OPTARG}&lt;BR /&gt;        ;;&lt;BR /&gt;    ?)&lt;BR /&gt;        printf "Usage: %s: [-t date] [-q value]\n" $0&lt;BR /&gt;        exit 2;;&lt;BR /&gt;    esac&lt;BR /&gt;done&lt;BR /&gt;if [ ! -z "${OPT_T}" ] ; then&lt;BR /&gt;        printf "Option -t with %s\n" ${VAL_T}&lt;BR /&gt;fi&lt;BR /&gt;if [ ! -z "${OPT_Q}" ] ; then&lt;BR /&gt;        printf "Option -q with %s\n" ${VAL_Q}&lt;BR /&gt;fi&lt;BR /&gt;shift $(( $OPTIND -1 ))&lt;BR /&gt;&lt;BR /&gt;if [ $# = 0 ]; then&lt;BR /&gt;    print  "No arguments remain"&lt;BR /&gt;else&lt;BR /&gt;    printf "Arguments remaining: %s\n" "$@"&lt;BR /&gt;fi&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;# ./example -q group=mine -t 02/12/2008 myfile&lt;BR /&gt;Option -t with 02/12/2008&lt;BR /&gt;Option -q with group=mine&lt;BR /&gt;Arguments remaining: myfile&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 12 Feb 2008 17:46:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/user-input-for-command-flags/m-p/4143808#M93423</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-02-12T17:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: User input for command flags</title>
      <link>https://community.hpe.com/t5/operating-system-linux/user-input-for-command-flags/m-p/4143809#M93424</link>
      <description>Thanks guys, this really helped!</description>
      <pubDate>Wed, 13 Feb 2008 22:41:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/user-input-for-command-flags/m-p/4143809#M93424</guid>
      <dc:creator>Vic S. Kelan</dc:creator>
      <dc:date>2008-02-13T22:41:29Z</dc:date>
    </item>
  </channel>
</rss>

