<?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: Problem on accepting a WORD in shell script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-on-accepting-a-word-in-shell-script/m-p/2828214#M937962</link>
    <description>&lt;BR /&gt;elif [ `echo $word | wc -w` != "1"  ]&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
    <pubDate>Thu, 17 Oct 2002 15:10:52 GMT</pubDate>
    <dc:creator>harry d brown jr</dc:creator>
    <dc:date>2002-10-17T15:10:52Z</dc:date>
    <item>
      <title>Problem on accepting a WORD in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-on-accepting-a-word-in-shell-script/m-p/2828210#M937958</link>
      <description>Problem on accepting a word in shell script&lt;BR /&gt;I'm suppose to allow my script to accept only ONE word but not more than one word. I don't want to use the usage of 'scriptfile [argument]'. I want my shell script to use the 'read' command. I've done something like this:&lt;BR /&gt;---------------&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;&lt;BR /&gt;echo "Enter a word: \c"&lt;BR /&gt;read word&lt;BR /&gt;if [ -z "$word" ]&lt;BR /&gt;   then&lt;BR /&gt;       echo "nothing is entered"&lt;BR /&gt;       exit 1&lt;BR /&gt;   elif [ ??? ] #how to do the checking here?&lt;BR /&gt;       then&lt;BR /&gt;           echo "cannot enter more than 1 word"&lt;BR /&gt;           exit 1&lt;BR /&gt;fi&lt;BR /&gt;echo "You entered: $word"&lt;BR /&gt;---------------&lt;BR /&gt;How do I write the proper elif statement that to ensure my word is not more than 2 word?&lt;BR /&gt;</description>
      <pubDate>Thu, 17 Oct 2002 14:57:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-on-accepting-a-word-in-shell-script/m-p/2828210#M937958</guid>
      <dc:creator>cybermilky</dc:creator>
      <dc:date>2002-10-17T14:57:07Z</dc:date>
    </item>
    <item>
      <title>Re: Problem on accepting a WORD in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-on-accepting-a-word-in-shell-script/m-p/2828211#M937959</link>
      <description>use the wc command with echo:&lt;BR /&gt;&lt;BR /&gt;`echo $word | wc -w`  you will get the number of words submitted... just check it against 1 and if it is not, exit with your error&lt;BR /&gt;&lt;BR /&gt;Ted</description>
      <pubDate>Thu, 17 Oct 2002 15:05:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-on-accepting-a-word-in-shell-script/m-p/2828211#M937959</guid>
      <dc:creator>Ted Ellis_2</dc:creator>
      <dc:date>2002-10-17T15:05:17Z</dc:date>
    </item>
    <item>
      <title>Re: Problem on accepting a WORD in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-on-accepting-a-word-in-shell-script/m-p/2828212#M937960</link>
      <description>While I would prefer to do this with regular expressions you can do it by attempting to read more than 1 var.&lt;BR /&gt;&lt;BR /&gt;echo "Enter a word: \c" &lt;BR /&gt;read word word2 word3 &lt;BR /&gt;&lt;BR /&gt;In this case, if more than one word is entered word2 will be a non-null value. If more that two words are entered word3 will be a non-null value. If three or more 'words' are entered ${word3} will contain everything past the first two 'words'.&lt;BR /&gt;</description>
      <pubDate>Thu, 17 Oct 2002 15:08:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-on-accepting-a-word-in-shell-script/m-p/2828212#M937960</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-10-17T15:08:30Z</dc:date>
    </item>
    <item>
      <title>Re: Problem on accepting a WORD in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-on-accepting-a-word-in-shell-script/m-p/2828213#M937961</link>
      <description>If you used "ksh" instead, you could do-&lt;BR /&gt;&lt;BR /&gt;read word&lt;BR /&gt;set -A wordlist $word&lt;BR /&gt;...&lt;BR /&gt;elif [ ${#wordlist[*]} &amp;gt; 1 ]&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;&lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Thu, 17 Oct 2002 15:09:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-on-accepting-a-word-in-shell-script/m-p/2828213#M937961</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2002-10-17T15:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: Problem on accepting a WORD in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-on-accepting-a-word-in-shell-script/m-p/2828214#M937962</link>
      <description>&lt;BR /&gt;elif [ `echo $word | wc -w` != "1"  ]&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Thu, 17 Oct 2002 15:10:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-on-accepting-a-word-in-shell-script/m-p/2828214#M937962</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2002-10-17T15:10:52Z</dc:date>
    </item>
    <item>
      <title>Re: Problem on accepting a WORD in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-on-accepting-a-word-in-shell-script/m-p/2828215#M937963</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;Yet another version.&lt;BR /&gt;&lt;BR /&gt;cnt=0&lt;BR /&gt;read a&lt;BR /&gt;for word in $a&lt;BR /&gt;do&lt;BR /&gt;cnt=$(($cnt + 1))&lt;BR /&gt;done&lt;BR /&gt;case $cnt in&lt;BR /&gt;0)&lt;BR /&gt;echo You must enter one word !&lt;BR /&gt;;;&lt;BR /&gt;1)&lt;BR /&gt;echo You entered $a&lt;BR /&gt;;;&lt;BR /&gt;*)&lt;BR /&gt;echo You entered $cnt words&lt;BR /&gt;;;&lt;BR /&gt;&lt;BR /&gt;esac&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 17 Oct 2002 18:09:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-on-accepting-a-word-in-shell-script/m-p/2828215#M937963</guid>
      <dc:creator>Leif Halvarsson_2</dc:creator>
      <dc:date>2002-10-17T18:09:05Z</dc:date>
    </item>
    <item>
      <title>Re: Problem on accepting a WORD in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-on-accepting-a-word-in-shell-script/m-p/2828216#M937964</link>
      <description>set word=`perl -le'while(print"Enter ONE word &amp;gt; "){$w=&lt;STDIN&gt;;$w=~/^\w+$/&amp;amp;&amp;amp;last}print$w`;&lt;/STDIN&gt;</description>
      <pubDate>Thu, 17 Oct 2002 18:23:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-on-accepting-a-word-in-shell-script/m-p/2828216#M937964</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2002-10-17T18:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: Problem on accepting a WORD in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-on-accepting-a-word-in-shell-script/m-p/2828217#M937965</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Another way.&lt;BR /&gt;&lt;BR /&gt;You can use $# parameter to look at the number of arguments.&lt;BR /&gt;&lt;BR /&gt;..&lt;BR /&gt;elif [ $# -gt  2 ]&lt;BR /&gt;then&lt;BR /&gt;echo "Cannot enter more than 2 words"&lt;BR /&gt;exit 1&lt;BR /&gt;..&lt;BR /&gt;&lt;BR /&gt;-Sri</description>
      <pubDate>Thu, 17 Oct 2002 19:27:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-on-accepting-a-word-in-shell-script/m-p/2828217#M937965</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2002-10-17T19:27:16Z</dc:date>
    </item>
    <item>
      <title>Re: Problem on accepting a WORD in shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-on-accepting-a-word-in-shell-script/m-p/2828218#M937966</link>
      <description>different solutions on that one. here are two of mine. The first on really checks if more than one word was entered. The second one simply cuts out the first word only.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;# first clear the screen&lt;BR /&gt;clear&lt;BR /&gt;# now ask for a word&lt;BR /&gt;echo "enter one word \c"&lt;BR /&gt;read w&lt;BR /&gt;# check if a word was entered&lt;BR /&gt;if test "$w" = ""&lt;BR /&gt;   then echo "nothing entered"&lt;BR /&gt;# count the words in the variable&lt;BR /&gt;   else if test `echo $w|wc -w` -gt 1&lt;BR /&gt;        then echo "more than one word2"&lt;BR /&gt;        else echo "one word entered"&lt;BR /&gt;        fi&lt;BR /&gt;fi&lt;BR /&gt;# **************************************&lt;BR /&gt;# another approach :&lt;BR /&gt;clear&lt;BR /&gt;echo "enter a word \c"&lt;BR /&gt;read w&lt;BR /&gt;# simply cut out the first word only and discard the rest&lt;BR /&gt;w2=`echo "$w"|cut -d' ' -f1`&lt;BR /&gt;if test "$w2" = ""&lt;BR /&gt;   then echo "nothing entered"&lt;BR /&gt;   else echo "here's your word : $w2"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;have fun&lt;BR /&gt;Sandro</description>
      <pubDate>Fri, 18 Oct 2002 05:49:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-on-accepting-a-word-in-shell-script/m-p/2828218#M937966</guid>
      <dc:creator>Sandro Schaer_1</dc:creator>
      <dc:date>2002-10-18T05:49:14Z</dc:date>
    </item>
  </channel>
</rss>

