1

This is the code so far:

#! /bin/bash

index=0
dirs=()    
dirs[0]=$(pwd)
size=${#dirs[*]} 
dirJump=" "

select choice in quit back jump $(ls -d */); do
        echo "###########################################################"
        ls -l | egrep -v '^d' | sed -e '1 d'                                    

        if [[ $choice == "quit" ]]; then
                break
        else if [[ $choice == "back" ]]; then
                size=${#dirs[*]}           
                if (( size > 1 )); then               
                        unset dirs[$(( ${#dirs[*]}-1 ))]
                        cd ${dirs[$(( ${#dirs[*]}-1 ))]}
                fi
        else if [[ $choice == "jump" ]]; then
                echo "Enter a directory to jump to: "
                read dirJump
                if (( ${#dirs[*]} == 10 )); then 
                        unset dirs[0]
                        cd $dirJump
                        dirs[$(${#dirs[*]})]="$dirJump" 
                else 
                        cd $dirJump
                        dirs[$(${#dirs[*]})]="$dirJump" 
                fi
        else
                echo "do other things"
        fi
done

When I test it, I get the error:

./dirNav.bash: line 35: syntax error near unexpected token `done'
./dirNav.bash: line 35: `done'

I thought you had to put "done" at the end of a select. What am I doing wrong?

1
  • Also just realized I can't use cd normally and took those lines out, but it still doesn't work Oct 26, 2015 at 20:48

2 Answers 2

2

Your if..fi construct has wrong keyword.

There is no keyword like else if in bash, it should be elif. So the problem is you have two else if keywords in your code, meke them as:

if ....; then
  ## something

elif ....; then
  ## something

elif ....; then
  ## something

else
  ## something
fi
0

The error has nothing to do with the "done" statement; this is a common type of error indicating that the interpreter got to the end, but was not expecting to get there yet. That is, it was expecting a terminator for a previous statement, but got to the end without ever getting what it expected.

I really don't think I should tell you the exact error, as finding errors is an important part of learning to program. Really, you should now have enough information to find it, but I'll give one more hint, and advise you to check all your if statements to make sure they terminate correctly

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .