Sponsored Content
Operating Systems Linux Ubuntu Bash to Ash, errors and adjustments Post 302906826 by fzivkovi on Monday 23rd of June 2014 07:17:19 PM
Old 06-23-2014
Bash to Ash, errors and adjustments

I wrote Bash script and now I want to convert it to Ash. One headache is this function:

Code:
do_adduser() {
    setaddprompt
    _arr_add=("Add manually" "Add via TXT" "return to main menu" "exit program")
    select add_action in "${_arr_add[@]}"
    do
        case "$REPLY" in
            1) do_manual_add ;;
            2) do_txt_add ;;
            3) return ;;
            4) exit 0 ;;
            *) badchoice ;;
        esac
        setaddprompt
    done
}

This function prints out the options and allows selection. First the ash error handler had me change the brackets as such

Code:
   _arr_add={"Add manually" "Add via TXT" "return to main menu" "exit program"}
    select add_action in "$(_arr_add[@])"

Which I think will be better. But now it is complaining about a missing "}" bracket.

Code:
line 72: syntax error: unexpected "do" (expecting "}")

When I get rid of the do statement, the error goes away. I tried adding a while before hand. It didn't make a difference so it's presently uncommented, and the code is bellow.

Code:
do_adduser() {                                                         
    setaddprompt                                                       
   # _arr_add={"Add manually" "Add via TXT" "return to main menu" "exit program"}
    #select add_action in "$(_arr_add[@])"                                       
    echo "Select Option:                                                         
1) Add manually                                                                  
2) Add via TXT                                                                   
3) Return to Main Menu                                                           
4) Exit Program                                                                  
"                                                                                
   # while[true];                                                                
     do;                                                                         
                                                                                 
        case "$REPLY" in                                                         
            1) do_manual_add ;;                                                  
            2) do_txt_add ;;                                                     
            3) return ;;                                                         
            4) exit 0 ;;                                                         
            *) badchoice ;;                                                      
        esac                                                                     
        setaddprompt                                                             
     done                                                                        
}

Does anybody know how I can change this to an 'ash' script successfully?

---------- Post updated at 06:17 PM ---------- Previous update was at 06:14 PM ----------

To summarize, I can't get the 'do' statement to work.

Last edited by Scrutinizer; 06-24-2014 at 03:48 AM.. Reason: CODE tags
 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Bash/Unix Command Errors

Hi all, I have major errors on entering the shell. On login I get: -bash: dircolors: command not found -bash: tr: command not found -bash: fgrep: command not found -bash: grep: command not found -bash: grep: command not found -bash: id: command not found -bash: # root@host # pwd /bin... (0 Replies)
Discussion started by: wcmmlynn
0 Replies

2. UNIX for Dummies Questions & Answers

Major OS errors/Bash errors help!!!!

Hi all, dummy here.... I have major errors on entering the shell. On login I get: -bash: dircolors: command not found -bash: tr: command not found -bash: fgrep: command not found -bash: grep: command not found -bash: grep: command not found -bash: id: command not found -bash: [: =: unary... (12 Replies)
Discussion started by: wcmmlynn
12 Replies

3. Shell Programming and Scripting

Why generate "ash and bash" different output for same bash script?

Hi, For my bash script, terminal with bash is generate an OK output and program works right. already, terminal with ash have "line 48: syntax error: Bad substitution" output and program don't work. :confused: (0 Replies)
Discussion started by: s. murat
0 Replies

4. Shell Programming and Scripting

Errors in bash with if statements

Hello everyone, I got this type of error when programming in bash new.bat: 16: cannot create : Directory nonexistent $bool new.bat: 37: Syntax error: "then" unexpected (expecting "fi") Does anyone know why? Here is my code #!bin/bash #function helps(){... (4 Replies)
Discussion started by: bbbash
4 Replies

5. UNIX for Dummies Questions & Answers

Differences in BASH and ASH shells regarding if command?

Guys I now have a script that's working in a BASH environment, however one line doesn't appear to be working on an embedded device that has a busybox therefore ASH shell. I've googled but there's very little I can find regarding the ASH shell. In BASH the following line works... if ] ;... (6 Replies)
Discussion started by: Bashingaway
6 Replies

6. Shell Programming and Scripting

Bash script errors when executing

I'm working on a script that will search through a directory for MKV files and remux them to MP4. I found a few other scripts around the net that do this, but they all have limitations that don't always get the job done. The main limitation I've found is that most scripts look for the video track... (2 Replies)
Discussion started by: rayne127
2 Replies

7. Shell Programming and Scripting

Bash Script to Ash (busybox) - Beginner

Hi All, I have a script that I wrote on a bash shell, I use it to sort files from a directory into various other directories. I have an variable set, which is an array of strings, I then check each file against the array and if it is in there the script sorts it into the correct folder. But... (5 Replies)
Discussion started by: sgtbobie
5 Replies

8. Ubuntu

Bash to ash port, character-matching problem

I'm trying to convert this working bash script into an Ash script, read -p "Username:" _username if ! ]]; then echo "Valid" else echo "INVALID" fi However, Ash does not recognize the "=~" character. How can I do this? Also, is there a good reference guide, so I... (5 Replies)
Discussion started by: fzivkovi
5 Replies

9. Ubuntu

Convert a bash to ash

hello everybody, i'm a beginner in ash and i want to convert this bash script to ash. this script send a xml file to a nagios server : #!/bin/bash PROGNAME=$(basename $0) RELEASE="Revision 0.3" print_release() { echo "$RELEASE" } print_usage() { echo "" echo "$PROGNAME... (6 Replies)
Discussion started by: mdijoux25
6 Replies
All times are GMT -4. The time now is 07:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy