<?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: branching in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/branching/m-p/5016873#M96772</link>
    <description>One possible way is to move the command &lt;BR /&gt;echo "listing file"&lt;BR /&gt;inside the case statement. For example:&lt;BR /&gt;&lt;BR /&gt;DISPLAY ()&lt;BR /&gt;{&lt;BR /&gt;echo "1. list file1"&lt;BR /&gt;echo "2. list file2"&lt;BR /&gt;echo "enter option? \c"&lt;BR /&gt;read input&lt;BR /&gt;case $input in&lt;BR /&gt;1) input_cmd="ls f1"&lt;BR /&gt;   echo "Listing file" ;;&lt;BR /&gt;2) input_cmd="ls f2"&lt;BR /&gt;   echo "Listing file" ;;&lt;BR /&gt;C) echo "cancelled"&lt;BR /&gt;return 0&lt;BR /&gt;;;&lt;BR /&gt;*) echo "incorrect option"&lt;BR /&gt;return 1&lt;BR /&gt;;;&lt;BR /&gt;esac&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;main script&lt;BR /&gt;DISPLAY</description>
    <pubDate>Tue, 05 Dec 2006 03:43:30 GMT</pubDate>
    <dc:creator>jnovak</dc:creator>
    <dc:date>2006-12-05T03:43:30Z</dc:date>
    <item>
      <title>branching</title>
      <link>https://community.hpe.com/t5/operating-system-linux/branching/m-p/5016870#M96769</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;I have a case statement in a function. I invoke it from the Main program and it works great except when I select option "C" to cancel or when I have a typ'O, it executes the next line "echo "Listing file"??? I don't want it to get to that line? &lt;BR /&gt;&lt;BR /&gt;DISPLAY ()&lt;BR /&gt;{&lt;BR /&gt;echo "1. list file1"&lt;BR /&gt;echo "2. list file2"&lt;BR /&gt;echo "enter option? \c"&lt;BR /&gt;read input&lt;BR /&gt;case $input in&lt;BR /&gt;        1) input_cmd="ls f1" ;;&lt;BR /&gt;        2) input_cmd="ls f2" ;;&lt;BR /&gt;        C) echo "cancelled"&lt;BR /&gt;           return 0&lt;BR /&gt;        ;;&lt;BR /&gt;        *) echo "incorrect option"&lt;BR /&gt;           return 1&lt;BR /&gt;        ;;&lt;BR /&gt;esac&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;main script&lt;BR /&gt;DISPLAY&lt;BR /&gt;echo "Listing file"</description>
      <pubDate>Mon, 04 Dec 2006 21:18:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/branching/m-p/5016870#M96769</guid>
      <dc:creator>lnl</dc:creator>
      <dc:date>2006-12-04T21:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: branching</title>
      <link>https://community.hpe.com/t5/operating-system-linux/branching/m-p/5016871#M96770</link>
      <description>First, you should change your logic just a bit so that a return of 0 indicates success; non-zero is a failure. This is in keeping with standard UNIX conventions.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;DISPLAY ()&lt;BR /&gt;{&lt;BR /&gt;  typeset -i FSTAT=0&lt;BR /&gt;echo "1. list file1"&lt;BR /&gt;echo "2. list file2"&lt;BR /&gt;echo "enter option? \c"&lt;BR /&gt;read input&lt;BR /&gt;case ${input} in&lt;BR /&gt;1) input_cmd="ls f1"&lt;BR /&gt;   ;;&lt;BR /&gt;2) input_cmd="ls f2"&lt;BR /&gt;   ;;&lt;BR /&gt;C) echo "cancelled"&lt;BR /&gt;   FSTAT=2&lt;BR /&gt;   ;;&lt;BR /&gt;*) echo "incorrect option"&lt;BR /&gt;   FSTAT=2&lt;BR /&gt;   ;;&lt;BR /&gt;esac&lt;BR /&gt;return ${FSTAT}&lt;BR /&gt;} # DISPLAY&lt;BR /&gt;&lt;BR /&gt;main script&lt;BR /&gt;XX=$(DISPLAY)&lt;BR /&gt;STAT=${?}&lt;BR /&gt;# ${XX} contains the stdout of DISPLAY (if any) and ${STAT} contains the return code.&lt;BR /&gt;# only do something if ${STAT} equals 0&lt;BR /&gt;if [[ ${STAT} -eq 0 ]]&lt;BR /&gt;  then&lt;BR /&gt;    echo "Listing file"&lt;BR /&gt;  fi&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 04 Dec 2006 21:36:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/branching/m-p/5016871#M96770</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-12-04T21:36:26Z</dc:date>
    </item>
    <item>
      <title>Re: branching</title>
      <link>https://community.hpe.com/t5/operating-system-linux/branching/m-p/5016872#M96771</link>
      <description>If you don't want to return from DISPLAY, you need to use exit rather than return.&lt;BR /&gt;&lt;BR /&gt;Or in Clay's example, you'll need extra checks in main.</description>
      <pubDate>Mon, 04 Dec 2006 23:40:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/branching/m-p/5016872#M96771</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2006-12-04T23:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: branching</title>
      <link>https://community.hpe.com/t5/operating-system-linux/branching/m-p/5016873#M96772</link>
      <description>One possible way is to move the command &lt;BR /&gt;echo "listing file"&lt;BR /&gt;inside the case statement. For example:&lt;BR /&gt;&lt;BR /&gt;DISPLAY ()&lt;BR /&gt;{&lt;BR /&gt;echo "1. list file1"&lt;BR /&gt;echo "2. list file2"&lt;BR /&gt;echo "enter option? \c"&lt;BR /&gt;read input&lt;BR /&gt;case $input in&lt;BR /&gt;1) input_cmd="ls f1"&lt;BR /&gt;   echo "Listing file" ;;&lt;BR /&gt;2) input_cmd="ls f2"&lt;BR /&gt;   echo "Listing file" ;;&lt;BR /&gt;C) echo "cancelled"&lt;BR /&gt;return 0&lt;BR /&gt;;;&lt;BR /&gt;*) echo "incorrect option"&lt;BR /&gt;return 1&lt;BR /&gt;;;&lt;BR /&gt;esac&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;main script&lt;BR /&gt;DISPLAY</description>
      <pubDate>Tue, 05 Dec 2006 03:43:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/branching/m-p/5016873#M96772</guid>
      <dc:creator>jnovak</dc:creator>
      <dc:date>2006-12-05T03:43:30Z</dc:date>
    </item>
    <item>
      <title>Re: branching</title>
      <link>https://community.hpe.com/t5/operating-system-linux/branching/m-p/5016874#M96773</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;different from switch/case statements in C(++) or (t)csh, a 'case' in (k)sh does NOT move to the next 'case'-label but behaves like a &lt;BR /&gt;&lt;BR /&gt;case 1:&lt;BR /&gt;     ...&lt;BR /&gt;     breaksw&lt;BR /&gt;case 2:&lt;BR /&gt;&lt;BR /&gt;to speak in csh language.&lt;BR /&gt;So presetting $RETURN like in Clay's response is the recommended way.&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Tue, 05 Dec 2006 03:56:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/branching/m-p/5016874#M96773</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2006-12-05T03:56:04Z</dc:date>
    </item>
    <item>
      <title>Re: branching</title>
      <link>https://community.hpe.com/t5/operating-system-linux/branching/m-p/5016875#M96774</link>
      <description>&amp;gt;Peter: So presetting $RETURN&lt;BR /&gt;&lt;BR /&gt;If you look very closely at the original example, the returns are meant to be exit.  And the other case labels are just meant to fall out of DISPLAY with an unchecked exit status and the real "return" value is in input_cmd.</description>
      <pubDate>Tue, 05 Dec 2006 04:04:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/branching/m-p/5016875#M96774</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2006-12-05T04:04:32Z</dc:date>
    </item>
    <item>
      <title>Re: branching</title>
      <link>https://community.hpe.com/t5/operating-system-linux/branching/m-p/5016876#M96775</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;read this line as&lt;BR /&gt;... presetting the returnvalue via $FSTAT ...&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Tue, 05 Dec 2006 04:07:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/branching/m-p/5016876#M96775</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2006-12-05T04:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: branching</title>
      <link>https://community.hpe.com/t5/operating-system-linux/branching/m-p/5016877#M96776</link>
      <description>Clay's example meets my goals.&lt;BR /&gt;I wanted the case statement to return not to exit.&lt;BR /&gt;&lt;BR /&gt;Clay,&lt;BR /&gt;10 points for you sir!&lt;BR /&gt;&lt;BR /&gt;Thanks to everyone who participated in this thread!!!</description>
      <pubDate>Tue, 05 Dec 2006 17:57:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/branching/m-p/5016877#M96776</guid>
      <dc:creator>lnl</dc:creator>
      <dc:date>2006-12-05T17:57:50Z</dc:date>
    </item>
  </channel>
</rss>

