Sponsored Content
Top Forums Shell Programming and Scripting Error Message in function causing failure..... Post 302690849 by Corona688 on Thursday 23rd of August 2012 12:31:38 PM
Old 08-23-2012
Quote:
Originally Posted by vgersh99
Not sure if ash supports 'select', but it might ease the menu creation and execution.
It doesn't unfortunately.

But since it supports functions, something similar can be built:

Code:
$ cat bb-select.sh

#!/bin/bb

bbselect () {
        local FS="$IFS";        IFS="|" # Split on pipes
        local VAR="$1";         shift   # Get var to save in
        local TITLES="$*"               # TITLES="title1|title2|title3"
        local N=1

        while [ "$#" -gt 0 ]            # Print all titles
        do
                printf "%2d)\t%s\n" "$N" "$1"
                let N=N+1;      shift
        done

        set -- $TITLES                  # $1="title1", $2="title2", ...
        IFS="$FS"                       # Put old splitter back

        read -p "? " REPLY < /dev/tty || return 1

        # Return error when given a non-number
        case "$REPLY" in
        [1-9])  ;;      [0-9][0-9])     ;;
        *)              return 1        ;;
        esac

        # Return error when given an out-of-range number
        [ "$REPLY" -lt 1 ]  && return 1
        [ "$REPLY" -gt $# ] && return 1

        # Look up the correct title text
        let N=REPLY-1
        [ "$N" -gt 0 ] && shift "$N"

        # Put the title text in the variable *named* in VAR
        read $VAR <<EOF
$1
EOF
        # Return success
        return 0
}

while ! bbselect X "Door 1" "Door 2" "Door 3"
do
        echo "Invalid reply $REPLY"
done

echo "Got value '$X' -- number $REPLY"

$ ./bb-select.sh

 1)     Door 1
 2)     Door 2
 3)     Door 3
? 0
Invalid reply 0
 1)     Door 1
 2)     Door 2
 3)     Door 3
? 50
Invalid reply 50
 1)     Door 1
 2)     Door 2
 3)     Door 3
? slartibartfast
Invalid reply slartibartfast
 1)     Door 1
 2)     Door 2
 3)     Door 3
? 3
Got value 'Door 3' -- number 3

$


Last edited by Corona688; 08-23-2012 at 01:40 PM..
 

10 More Discussions You Might Find Interesting

1. Solaris

Explorer causing syslog error

Hi there, I have upgraded my explorer (SUNWexplo) on a solaris 10 Sparc box from version 3.4 to the latest version (5.5) . However im a little concerned, whenever I run the new explorer either manually or scheduled, I get a syslog event as follows 1 in 0:08:31: Sep 22 17:00:15 fmy.machine.com... (8 Replies)
Discussion started by: hcclnoodles
8 Replies

2. Solaris

Memory error causing reboot

Hi there I have a box that at 4pm started recieving soft errors on a DIMM, normally this is ok and we have time to swap it out. But I got the following error which caused the box to reboot NOTE: there were abount 6 or 7 normal "soft error encountered" messages before this one Nov 7... (1 Reply)
Discussion started by: hcclnoodles
1 Replies

3. Solaris

error message rmclomv ... SC Login Failure for user Please login:

Hello World ~ HW : SUN Fire V240 OS : Solaris 8 Error message prompts 'rmclomv ... SC login failure ...' on terminal. and Error Message prompts continually 'SC Login Failure for user Please login:' on Single Mode(init S) The System is in normal operation, though In case of rain, Can... (1 Reply)
Discussion started by: lifegeek
1 Replies

4. Shell Programming and Scripting

Function not found message

I have shell script as below: #!/bin/ksh #set -xv function set_variable { VARIABLE_NAME=$1 CURRENT_PATH=`pwd` if ; then echo "\nconfiguration_file.lst file not found in $CURRENT_PATH/common/common_scripts" exit 1; fi VARIABLE_COUNT=`cat... (2 Replies)
Discussion started by: findprakash
2 Replies

5. Shell Programming and Scripting

SendMail Function Failure

Hi All, Background: We use SendMail function (given below) to send emails to users. The email address are obtained as ouptut of a stored procedure in sybase. We have defined a SendMail function as below in a .pm file and it is used in a .pl script. Code Snippet: sub SendMail { ... (1 Reply)
Discussion started by: vigdmab
1 Replies

6. UNIX for Dummies Questions & Answers

How to get failure notice message when email is not sent.

I am using mailx command to send emails from the Unix command prompt. Whenever email is not sent it is not giving me any message "Email not sent" or failure delivery notice for the wrong email addresses. When I give correct email address I am able to receive them correctly. Can anyone please... (0 Replies)
Discussion started by: szc0025
0 Replies

7. Shell Programming and Scripting

Spaced input causing awk error

Hi all, Just want to say thanks for the great forum you have here, the old topics and posts have helped tremendously. So much so that I have managed to figure a lot out just by researching. However, I'm having a small issue that I simply can't find the answer to. (4 Replies)
Discussion started by: whyte_rhyno
4 Replies

8. Shell Programming and Scripting

Bash function accepting list of strings and error message

I have a variable strLst containing a list of strings. I want to create a function that takes the list and an error message. If the number of strings is 0 or greater than 1, I print the error message. (1 Reply)
Discussion started by: kristinu
1 Replies

9. Shell Programming and Scripting

Help with FTP Script which is causing "syntax error: unexpected end of file" Error

Hi All, Please hav a look at the below peice of script and let me know if there are any syntax errors. i found that the below peice of Script is causing issue. when i use SFTP its working fine, but there is a demand to use FTP only. please find below code and explain if anything is wrong... (1 Reply)
Discussion started by: mahi_mayu069
1 Replies

10. Shell Programming and Scripting

Pipe causing last command error to not function

Hi I am quite new to scripting and cannot work out how to do the following - I want to pipe to a log file and then use the "last statement error" in an if statement after, and this doesn't work because it checks the pipe statement instead of the script. Example: executteTheScript $var |... (4 Replies)
Discussion started by: erjorgito
4 Replies
rc.config(4)						     Kernel Interfaces Manual						      rc.config(4)

NAME
rc.config, rc.config.d - files containing system configuration information SYNOPSIS
DESCRIPTION
The system configuration used at startup is contained in files within the directory The file sources all of the files within and and exports their contents to the environment. /etc/rc.config The file is a script that sources all of the scripts, and also sources To read the configuration definitions, only this file need be sourced. This file is sourced by whenever it is run, such as when the command is run to transition between run states. Each file that exists in is sourced, without regard to which startup scripts are to be executed. /etc/rc.config.d The configuration information is structured as a directory of files, rather than as a single file containing the same information. This allows developers to create and manage their own configuration files here, without the complications of shared ownership and access of a common file. /etc/rc.config.d/* Files This is where files containing configuration variable assignments are located. Configuration scripts must be written to be read by the POSIX shell, and not the Bourne shell, or In some cases, these files must also be read and possibly modified by control scripts or the sam program. See sd(4) and sam(1M). For this reason, each variable definition must appear on a separate line, with the syntax: No trailing comments may appear on a variable definition line. Comment statements must be on separate lines, with the comment character in column one. This example shows the required syntax for configuration files: Configuration variables may be declared as array parameters when describing multiple instances of the variable configuration. For example, a system may contain two network interfaces, each having a unique IP address and subnet mask (see ifconfig(1M)). An example of such a dec- laration is as follows: Note that there must be no requirements on the order of the files sourced. This means configuration files must not refer to variables defined in other configuration files, since there is no guarantee that the variable being referenced is currently defined. There is no protection against environment variable namespace collision in these configuration files. Programmers must take care to avoid such prob- lems. /etc/TIMEZONE The file contains the definition of the environment variable. This file is required by POSIX. It is sourced by at the same time the files are sourced. SEE ALSO
rc(1M). rc.config(4)
All times are GMT -4. The time now is 11:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy