Score:-1

Shell Script throws error "unexpected end of file"

ar flag

I have been working on this script for quite some time.But I have been getting errors.The script is supposed to use tmpfs to quickly transfer files from point A to point B. The script is shown below.

#!/bin/bash
cat .ramv &> /dev/null
if [[ $? = "1" ]]; then
    dialog --yesno "I have detected that you have not used this program before.Would you like to setup the ramdisk and install the needed packages?" 24 80
else
if [[ $? = "0" ]]; then
tail --lines=+27 ~/ramv.sh | bash 
fi
fi
if [[ $? = "1" ]]; then
    dialog --msgbox "This command will not work if you dont install the packages and the ramdisk." 24 80
else
if 
    dialog --yesno "The ramdisk size defaults to 2GB.Do you have more than 4GB of RAM in total?" 24 80
    if [[ $? = "1" ]]; then
    dialog --msgbox "This command will not work if you do not have more than 4GB of RAM" 24 80
    else
    dialog --msgbox "I need root accsess for this to work.Could you please enter your root password?" 24 80
    sudo dialog --msgbox "Thanks! We can now commence with creating the ramdisk" 24 80
    sudo mkdir /mnt/tmp
    sudo mount -t tmpfs -o size=2g tmpfs /mnt/tmp
    sudo echo "
tmpfs  /mnt/tmp  tmpfs  rw,size=2G  0   0" >> /etc/fstab
dialog --msgbox "The setup has commpleted. A help file has been writen to your home folder." 24 80
touch .ramv
fi
mv $1 /mnt/tmp
mv /mnt/tmp/$1 $2

The error is shown below

eli@eli-desktop:~$ ./ramv.sh
./ramv.sh: line 29: syntax error: unexpected end of file
eli@eli-desktop:~$ 

Can someone show me why this error is happening and how to fix it?

hr flag
Well, I count 5 "if"s and only 3 "fi"s - I suggest starting by indenting your code consistently, that should help you to figure out where the missing ones need to go
FedKad avatar
cn flag
Does this answer your question? [Know whether the shell script contains syntax error without running the script](https://askubuntu.com/questions/482687/know-whether-the-shell-script-contains-syntax-error-without-running-the-script) See second answer!
waltinator avatar
it flag
Always paste your script into `https://shellcheck.net`, a syntax checker, or install `shellcheck` locally. Make using `shellcheck` part of your development process.
Hannu avatar
ca flag
`sudo echo "` <- this line will cause trouble.
Eli Thrash avatar
ar flag
When i add more fi's it says `./ramv.sh: line 27: syntax error near unexpected token 'fi' ` `./ramv.sh: line 27: fi' `
Eli Thrash avatar
ar flag
now it works.But how do i make it skip the dialog commands after setup?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.