LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-18-2009, 11:46 AM   #1
camilla_darling
LQ Newbie
 
Registered: Mar 2009
Posts: 2

Rep: Reputation: 0
case problems when scripting in bash


I'm writing a text-based user interface script in bash and this is how far I have gotten.
Now I get the message that there is a syntax error where i have an unexpected }.
it is marked with "# here is the error" in the code.
Why is this a syntax error?
I have the matching { at the beginning of the function file_function.
and if you have any suggestions on how to complete the script you are more than welcome to tell me.
I am a girl who just started to script and to make my own programs.
It's interesting but difficult, please help!

Thanks to all who reads this.


Code:
#!/bin/bash
# a menu based text-user-interface

main_function()
{


file_function()
{
copy_function()
{
i_copy_function()
{

echo"Type in the files to copy:"

read files

cp -i $files

}
backup_function()
{

echo "Type in the files to copy:"

read files

cp -b $files

}
preserve_function()
{
echo "Type in the files to copy:"

read files

cp -p $files
}
recursive_function()
{
echo "Type in the files to copy:"

read files

cp -r $files
}

echo "Copy files submenu"
echo "1. Interactive copy, answer yes or no (y/n) before doing the copy"
echo "2. Make backups of existing destination files"
echo "3. Preserve file attributes"
echo "4. Do a recursively copy"
echo "5. Cancel the copy and return to main menu"
echo "0. Exit the program"
echo "Enter your choice:"

read copy_choice

case $copy_choice in
    1) i_copy_function
        ;;

    2) backup_function
        ;;

    3) preserve_function
        ;;

    4) recursive_function
        ;;

    5) main_function
        ;;

    0) exit
        ;;

} # here is the error

rename_function()
{

echo "Rename files submenu"
echo "
}

move_function()
{

}

print_function()
{

}

edit_function()
{

}
echo "File operation choices:"
echo "1. Copy"
echo "2. Rename"
echo "3. Move"
echo "4. Print"
echo "5. Edit"
echo "6. Go back to main menu"
echo "0. Exit the program"
echo "Enter you choice:"

read file_choice

case $file_choice in
    1) copy_function
        ;;

    2) rename_function
        ;;

    3) move_function
        ;;

    4) print_function
        ;;

    5) edit_function
        ;;

    6) main_function


    0) exit
        ;;
}

directory_function()
{

}

process_function()
{

}

search_function()
{

}



echo "Welcome to my text-based user interface!"
echo "Enter your choice:"
echo "1. File operations"
echo "2. Directory operations"
echo "3. Process management"
echo "4. Search operations"
echo "0. Exit the program"


read choice


case $choice in
    1) file_function     # call the file_function() function
       ;;

    2) directory_function     # call the directory_function() function
       ;;

    3) process_function  #call the process_function() function
       ;;

    4) search_function  #call the search_function() function
        ;;

    0) exit             #exit the program
       ;;

    *) exit            #in case the user types the wrong number
       ;;
esac

}

Last edited by camilla_darling; 03-19-2009 at 12:10 PM.
 
Old 03-18-2009, 12:36 PM   #2
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
Please edit your post to enclose all that in CODE tags.
You need to have a closing '}' for each opeing '{'. Looks like several are missing.
Also, be sure to put *something* inside the function -even if it's a dummy command like 'true' or 'echo hello from $FUNCNAME'.
 
Old 03-19-2009, 12:37 PM   #3
camilla_darling
LQ Newbie
 
Registered: Mar 2009
Posts: 2

Original Poster
Rep: Reputation: 0
case-problem solved!

Thank you for your answer, the problem is now solved
My boyfriend tipped me off to end my case with esac.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Korn Shell Scripting case statement help!! wfdeng117 Programming 3 07-22-2008 10:51 AM
Case Statement With Aix Ksh Scripting ']['HeBroken AIX 2 02-09-2005 12:44 PM
KSH Scripting case statement..... ']['HeBroken Programming 1 12-10-2004 10:38 AM
I need a scripting lanuage with case and shell commands rob.rice Programming 1 04-18-2004 02:17 PM
Shell scripting yes/no case? Squeak2704 Programming 1 04-09-2004 02:05 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration