-2

I have typed out the code for this mychoice.sh bash example and I keep getting the syntax error: unexpected end of file.

Am I missing something?

mychoice.sh

#!/bin/bash

E='echo -e';e='echo -en';trap ";exit" 2
ESC=$( $e "\e")
TPUT(){ $e "\e[${1};${2}H";}
CLEAR(){ $e "\ec";}
CIVIS(){ $e "\e[25l"}
DRAW(){ $e "\e%\e(0";}
WRITE(){ $e "\e(B";}
MARK(){ $e "\e[7m";}
UNMARK(){ $e "\e[27m";}
R(){ CLEAR ;stty sane;$e "\ec\e[37;44m[J";};
HEAD(){ DRAW
    for each in $(seq 1 13);do
    $E "   x                    x"
    done
    WRITE;MARK;TPUT; 1 5
    $E "BASH SELECTION MENU         ";UNMARK;}
    i=0; CLEAR; CIVIS;NULL=/dev/null
FOOT(){ MARK;TPUT 13 5
    printf "ENTER - SELECT,NEXT         ";UNMARK;}
ARROW(){ read -s -n3 key 2>/dev/null >&2
     if [[$key = $ESC[A ]];then echo up;fi
     if [[$key = $ESC[B ]];then echo dn;fi;}
M0(){ TPUT  4 20; $e "Login info";}
M1(){ TPUT  5 20; $e "Network";}
M2(){ TPUT  6 20; $e "Disk";}
M3(){ TPUT  7 20; $e "Routing";}
M4(){ TPUT  8 20; $e "Time";}
M5(){ TPUT  9 20; $e "About  ";}
M6(){ TPUT 10 20; $e "Exit   ";}
LM=6
MENU(){ for each in $(seq 0 $LM);do M${each};done;}
POS(){ if [[ $cur == up ]];then ((i--));fi
    if [[ $cur == dn ]];then ((i++));fi
    if [[ $i -lt 0 ]];then i=$LM;fi
    if [[ $i -gt $LM ]];then i=0;fi;}
REFRESH(){ after=$((i+1)); before=$((i-!))
    if [[ $before -lt 0 ]];then before=$LM;fi
    if [[ $after -gt 0 ]];then after=0;fi
    if [[ $j -lt $i ]];then UNMARK;M$before;else UNMARK;M$after;fi
    if [[ $after -eq 0 ]] || [$before -eq $LM ];then 
        UNMARK; M$before; M$after;fi;j=$i;UNMARK;M$before;M$after;}
INIT(){ R;HEAD;FOOT;MENU;}
SC(){ REFRESH;MARK;$S;$b;cur='ARROW';}
ES(){ MARK;$e "ENTER = main menu ";$b;read;INIT;};INIT
while [[ "$0" != " " ]]; do case $i in
    0) S=M2;SC;if [[ $cur == "" ]];then R;$e "\nS(w     )\n";ES;fi;;
    1) S=M2;SC;if [[ $cur == "" ]];then R;$e "\nS(ifconfig  )\n";ES;fi;;
    2) S=M2;SC;if [[ $cur == "" ]];then R;$e "\nS(df -h )\n";ES;fi;;
    3) S=M2;SC;if [[ $cur == "" ]];then R;$e "\nS(route -n  )\n";ES;fi;;
    4) S=M2;SC;if [[ $cur == "" ]];then R;$e "\nS(date  )\n";ES;fi;;
    5) S=M2;SC;if [[ $cur == "" ]];then R;$e "\nS($e by oTo )\n";ES;fi;;
    6) S=M2;SC;if [[ $cur == "" ]];then R;exit 0;fi;; 
esac;POS;done;
  • 4
    Can I suggest you use www.shellcheck.net and then post here if you need help interpreting the results? – steeldriver Dec 2 '17 at 18:01
3

You can run your script through shell checker:

$ shellcheck myscript

Line 7:
CIVIS(){ $e "\e[25l"}
^-- SC1009: The mentioned parser error was in this function.
       ^-- SC1073: Couldn't parse this brace group.
                    ^-- SC1083: This } is literal. Check expression (missing ;/\n?) or quote it.

Line 23:
         if [[$key = $ESC[A ]];then echo up;fi
            ^-- SC1035: You need a space after the [[ and before the ]].

Line 24:
         if [[$key = $ESC[B ]];then echo dn;fi;}
            ^-- SC1035: You need a space after the [[ and before the ]].

Line 42:
        if [[ $after -eq 0 ]] || [$before -eq $LM ];then 
                                 ^-- SC1035: You need a space after the [ and before the ].

Line 56:

^-- SC1056: Expected a '}'. If you have one, try a ; or \n in front of it.
^-- SC1072: Missing '}'. Fix any mentioned problems and try again.

$ 

As the shell checker tells us you need to change line 7 from:

CIVIS(){ $e "\e[25l"}

to:

CIVIS(){ $e "\e[25l";}
1

Couple of comments:

  • Don't use variables for calling commands as in E='echo -e';e='echo -en'; use functions instead with at least somewhat descriptive names. Alternatively use printf if you need backslash interpretation
  • add spaces after test command, [ and [[ (and yes, it's not an operator, it's actually a command called "test" and [ is just a shorthand for it, that's why you need spaces)
  • use lowercase letters for function and variable names ( this will avoid confusion with standard environment variables )
  • in addition to what WinEunuuchs2Unix already posted, shellcheck also notes one more thing:

    SC(){ REFRESH;MARK;$S;$b;cur='ARROW';}
                          ^-- SC2154: b is referenced but not assigned.
    

    This variable $b is not assigned, so consider either getting rid of it if it's not going to be used or assign some value to it.

  • The code I typed out was from the Linux Manual Vol 48 by BDM Publications. I do wonder how they got $b to work? – Niall Magner Dec 3 '17 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.