<?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: Shell script:  get default value in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/shell-script-get-default-value/m-p/3593040#M104010</link>
    <description>You can also use this as,&lt;BR /&gt;&lt;BR /&gt;# cat test.sh&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;echo "Choice A,B,C,D(default)"&lt;BR /&gt;choice="";&lt;BR /&gt;read choice;&lt;BR /&gt;&lt;BR /&gt;case ${choice} in&lt;BR /&gt;&lt;BR /&gt;A)&lt;BR /&gt;  echo "Choice A";&lt;BR /&gt;  ;;&lt;BR /&gt;&lt;BR /&gt;B)&lt;BR /&gt;  echo "Choice B";&lt;BR /&gt;  ;;&lt;BR /&gt;&lt;BR /&gt;C)&lt;BR /&gt;  echo "Choice C";&lt;BR /&gt;  ;;&lt;BR /&gt;&lt;BR /&gt;*)&lt;BR /&gt;  echo "Choice D";&lt;BR /&gt;  ;;&lt;BR /&gt;esac&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;hth.&lt;BR /&gt;</description>
    <pubDate>Mon, 01 Aug 2005 04:50:31 GMT</pubDate>
    <dc:creator>Muthukumar_5</dc:creator>
    <dc:date>2005-08-01T04:50:31Z</dc:date>
    <item>
      <title>Shell script:  get default value</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-get-default-value/m-p/3593037#M104007</link>
      <description>I would like to create a shell script that will do the following:&lt;BR /&gt;&lt;BR /&gt;su - username&lt;BR /&gt;&lt;BR /&gt;A list of choices will be shown and one of the choices is the default.  Example is:&lt;BR /&gt;&lt;BR /&gt;Choice A&lt;BR /&gt;Choice B&lt;BR /&gt;Choice C&lt;BR /&gt;Choice D(Default)&lt;BR /&gt;&lt;BR /&gt;Choose option or Choice D(Default)&lt;BR /&gt;&lt;BR /&gt;I'd like to get the default option so that I will not be asked for any inputs in the script.&lt;BR /&gt;&lt;BR /&gt;How can I do this is my script?&lt;BR /&gt;&lt;BR /&gt;Help please!!!&lt;BR /&gt;</description>
      <pubDate>Sat, 30 Jul 2005 00:02:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-get-default-value/m-p/3593037#M104007</guid>
      <dc:creator>shasha_1</dc:creator>
      <dc:date>2005-07-30T00:02:41Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script:  get default value</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-get-default-value/m-p/3593038#M104008</link>
      <description>Sorry, choices are like this:&lt;BR /&gt;&lt;BR /&gt;Choice A&lt;BR /&gt;Choice B&lt;BR /&gt;Choice C&lt;BR /&gt;Choice D&lt;BR /&gt;&lt;BR /&gt;Choose option or [Choice D]&lt;BR /&gt;&lt;BR /&gt;If I just press enter, the default choice will be given to me, which is Choice D.&lt;BR /&gt;&lt;BR /&gt;Again,  how do I set this in my script so that I will not be prompted for any input and whatever is the default will be taken?&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 30 Jul 2005 00:05:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-get-default-value/m-p/3593038#M104008</guid>
      <dc:creator>shasha_1</dc:creator>
      <dc:date>2005-07-30T00:05:27Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script:  get default value</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-get-default-value/m-p/3593039#M104009</link>
      <description>This looks suspiciously like asking free answers for a "Shell Scripting 101" exercise, but here goes...&lt;BR /&gt;&lt;BR /&gt;You must first display the list of choices, then receive user's input, and finally choose what to do based on the input. &lt;BR /&gt;&lt;BR /&gt;When you have to select just one thing among many, the "case ... esac" is often the best structure. &lt;BR /&gt;&lt;BR /&gt;The basic structure would be like this:&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;echo "Choose A, B, C or D:"&lt;BR /&gt;read choice &lt;BR /&gt;case "$choice" in&lt;BR /&gt;  A|a) &lt;BR /&gt;    echo "you chose A" &lt;BR /&gt;    ;;&lt;BR /&gt;  B|b)&lt;BR /&gt;    echo "you chose B"&lt;BR /&gt;    ;;&lt;BR /&gt;  C|c)&lt;BR /&gt;    echo "you chose C"&lt;BR /&gt;    ;;&lt;BR /&gt;  *)&lt;BR /&gt;    echo "you chose D, which is the default"&lt;BR /&gt;    ;;&lt;BR /&gt;esac&lt;BR /&gt;&lt;BR /&gt;Note that you need to explicitly check for upper and lower case characters ("a" is not the same as "A"). The last choice is picked if none of the previous ones matched, because "*" always matches.&lt;BR /&gt;</description>
      <pubDate>Mon, 01 Aug 2005 04:24:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-get-default-value/m-p/3593039#M104009</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2005-08-01T04:24:04Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script:  get default value</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-get-default-value/m-p/3593040#M104010</link>
      <description>You can also use this as,&lt;BR /&gt;&lt;BR /&gt;# cat test.sh&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;echo "Choice A,B,C,D(default)"&lt;BR /&gt;choice="";&lt;BR /&gt;read choice;&lt;BR /&gt;&lt;BR /&gt;case ${choice} in&lt;BR /&gt;&lt;BR /&gt;A)&lt;BR /&gt;  echo "Choice A";&lt;BR /&gt;  ;;&lt;BR /&gt;&lt;BR /&gt;B)&lt;BR /&gt;  echo "Choice B";&lt;BR /&gt;  ;;&lt;BR /&gt;&lt;BR /&gt;C)&lt;BR /&gt;  echo "Choice C";&lt;BR /&gt;  ;;&lt;BR /&gt;&lt;BR /&gt;*)&lt;BR /&gt;  echo "Choice D";&lt;BR /&gt;  ;;&lt;BR /&gt;esac&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;hth.&lt;BR /&gt;</description>
      <pubDate>Mon, 01 Aug 2005 04:50:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-get-default-value/m-p/3593040#M104010</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-08-01T04:50:31Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script:  get default value</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-get-default-value/m-p/3593041#M104011</link>
      <description>You can also use if-elif-else for this as,&lt;BR /&gt;&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;echo "Choice A,B,C,D(default)"&lt;BR /&gt;choice="";&lt;BR /&gt;&lt;BR /&gt;read choice;&lt;BR /&gt;&lt;BR /&gt;choice=$(echo $choice | tr "[a-z]" "[A-Z]")&lt;BR /&gt;&lt;BR /&gt;if [[ ${choice} = "A" ]]&lt;BR /&gt;then&lt;BR /&gt;&lt;BR /&gt; echo "Choice A"&lt;BR /&gt;&lt;BR /&gt;elif [[ ${choice} = "B" ]]&lt;BR /&gt;then&lt;BR /&gt;&lt;BR /&gt; echo "Choice B"&lt;BR /&gt;&lt;BR /&gt;elif [[ ${choice} = "C" ]]&lt;BR /&gt;then&lt;BR /&gt;&lt;BR /&gt; echo "Choice C"&lt;BR /&gt;&lt;BR /&gt;else&lt;BR /&gt;&lt;BR /&gt; echo "Choice D - Default"&lt;BR /&gt;&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;# END #&lt;BR /&gt;&lt;BR /&gt;hth.</description>
      <pubDate>Mon, 01 Aug 2005 06:12:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-get-default-value/m-p/3593041#M104011</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-08-01T06:12:34Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script:  get default value</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-get-default-value/m-p/3593042#M104012</link>
      <description>Hi Donna, is this for a generic user where they wont have prompt access or it is just to set different type environment.&lt;BR /&gt;first to generic user with out prompt access.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;BOLD=`tput 'smso'`&lt;BR /&gt;NORMAL=`tput 'rmso'`&lt;BR /&gt;&lt;BR /&gt;while :&lt;BR /&gt;do&lt;BR /&gt;echo " &lt;BR /&gt;        Choose option&lt;BR /&gt;   A ) Do AAAAA&lt;BR /&gt;   B ) Do BBBBB&lt;BR /&gt;   C ) Do CCCCC&lt;BR /&gt;   D ) $BOLD Do BBBBB $NORMAL&lt;BR /&gt;   X ) eXit&lt;BR /&gt;    Choce or Enter to default option :&lt;BR /&gt;&lt;BR /&gt;"&lt;BR /&gt;  read OPTION&lt;BR /&gt;      if [ $OPTION = "" ] ; then&lt;BR /&gt;            OPTION=D&lt;BR /&gt;      fi&lt;BR /&gt;case $OPTION in&lt;BR /&gt;        a | A ) echo "Running ....AAAA" ; your command here ;;&lt;BR /&gt;        b | B ) echo "Running ....BBBB" ;&lt;BR /&gt;your command here ;;&lt;BR /&gt;        c | C ) echo "running ....CCCC" ;&lt;BR /&gt;your command here ;;&lt;BR /&gt;        d | D ) echo "Running ....DDDD" ; your command here ;;&lt;BR /&gt;        x | X ) exit 1;;&lt;BR /&gt;            * ) echo "Option $OPTION not available try again" ;;&lt;BR /&gt;esac&lt;BR /&gt;   &lt;BR /&gt;&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;and you can edit the .profile file and add the following line line at the end&lt;BR /&gt;&lt;BR /&gt;exec my-script-name&lt;BR /&gt;&lt;BR /&gt;Options to source environment it is almost the same&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;BOLD=`tput 'smso'`&lt;BR /&gt;NORMAL=`tput 'rmso'`&lt;BR /&gt;&lt;BR /&gt;echo " &lt;BR /&gt;        Choose option&lt;BR /&gt;   A ) Source environment a&lt;BR /&gt;   B ) Source environment b&lt;BR /&gt;   C ) Source environment c&lt;BR /&gt;   D ) $BOLD Source environment d $NORMAL&lt;BR /&gt;   &lt;BR /&gt;    Choce or Enter to default option :&lt;BR /&gt;&lt;BR /&gt;"&lt;BR /&gt;  read OPTION&lt;BR /&gt;      if [ $OPTION = "" ] ; then&lt;BR /&gt;            OPTION=D&lt;BR /&gt;      fi&lt;BR /&gt;case $OPTION in&lt;BR /&gt;        a | A ) echo "Running ....AAAA" ; your command here ;;&lt;BR /&gt;        b | B ) echo "Running ....BBBB" ;&lt;BR /&gt;your command here ;;&lt;BR /&gt;        c | C ) echo "running ....CCCC" ;&lt;BR /&gt;your command here ;;&lt;BR /&gt;        d | D ) echo "Running ....DDDD" ; your command here ;;&lt;BR /&gt;            * ) echo "Option $OPTION not available try again" ;;&lt;BR /&gt;&lt;BR /&gt;esac&lt;BR /&gt;   &lt;BR /&gt;I hope it helps&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 09 Aug 2005 09:55:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-get-default-value/m-p/3593042#M104012</guid>
      <dc:creator>Juan M Leon</dc:creator>
      <dc:date>2005-08-09T09:55:17Z</dc:date>
    </item>
  </channel>
</rss>

