multiple lines inside a case statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting multiple lines inside a case statement
# 1  
Old 04-23-2010
multiple lines inside a case statement

Code:
echo "please enter ur choice..
1.      Make a file.
2.      Display contents
3.      Copy the file
4.      Rename the file
5.      Delete the file
6.      Exit"
read choice
case $choice in
        1 ) echo enter the file name
        read fname
        if [ -e $fname ]
        then
        echo file name already exists
        else
        `touch $fname`
        echo the file $fname has got created.. plz enter  something               
read content
        cp content $fname ;;
        2 ) echo enter the file name to be displayed
        read fname
        if [ -e $fname ]
        then
        echo contents of the file $fname is :
        `cat $fname`;;
        3 ) echo under construction ;;
        4 ) echo under construction ;;
        5 ) echo under construction ;;
        6 ) echo "bye !!" ; exit;;
        * ) somethinggggggggg?? ;;
esac

###################################
i am getting error here because of ;;
Am i supposed to provide ;; at the end of every line or wat?? plz guide

Last edited by jim mcnamara; 04-23-2010 at 08:24 AM.. Reason: code tags please
# 2  
Old 04-23-2010
No, only at the end.

You're missing an fi in your first and second cases.

And there's no need to use backticks to execute cat and touch. They can execute all by themselves Smilie

Last edited by Scott; 04-23-2010 at 08:31 AM..
# 3  
Old 04-23-2010
thanks Smilie
its done now.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multiple conditions inside if statement

I was trying to write multiple conditions inside the if statement but its not working. export VAR_NM=abc.txt export CURR_DT=20131011 export PREV_DT=20131012 if && then echo "Yes" else echo "NO" fi It should return Yes but returning NO always.Appreciate any help. (3 Replies)
Discussion started by: dr46014
3 Replies

2. Shell Programming and Scripting

Use sqlplus statement inside case sentence

Hello, I have a problem. I want to launch a different sql queries for different shell parameter values, something like this. #/bin/bash case $1 in "A") sqlplus -s user/pass << SQL query A; SQL "B") sqlplus -s user/pass << SQL2 ... (3 Replies)
Discussion started by: Vares
3 Replies

3. Shell Programming and Scripting

Multiple conditions inside my if statement

Hello, I am using shell scripting and I am recieving odd results from my if statement if I want it to enter the loop only if L1 is equal to zero and one of the other criteria are filled, however it is entering at other times as well. What can i do to fix this? i tried seperating it... (6 Replies)
Discussion started by: ryddner
6 Replies

4. Shell Programming and Scripting

Regular expression inside case statement notworking

I have the following script: For catching errors like: But the regular expression ERROR*memory inside case doesn't seem to be working. The output of bash -x scriptname is: Please help (5 Replies)
Discussion started by: proactiveaditya
5 Replies

5. Shell Programming and Scripting

Can't print multiple lines inside awk :(

Hi Friends, I have small issue with following code snippet. I am trying call one function inside awk in which the function inturn will echo few lines. However when i ran script its throwing an error saying "nawk: syntax error at source line 1". #!/bin/sh eval input=$@ while read... (3 Replies)
Discussion started by: Shahul
3 Replies

6. Shell Programming and Scripting

Multiple conditions in a CASE statement

is it possible to use multiple conditions in a CASE statement? And if so, what is the syntax? I'm trying to use one but can't seem to get it right. I want the statement to be CASE $vendor OR $alias condition 1) statements; condition 2) statements; etc. esac but I keep... (25 Replies)
Discussion started by: Straitsfan
25 Replies

7. Shell Programming and Scripting

How do you use pull data from multiple lines to do a for statement?

Guys I am having a problem with being able to find missing monitors in a configuration check script I am trying to create for accountability purposes for managing a large number of systems. What I am trying to do is run a script that will look at the raw config data in a file and pull all the pool... (7 Replies)
Discussion started by: scottzx7rr
7 Replies

8. Shell Programming and Scripting

Case inside case?

Im new to unix and shell scripting. I am required to write a program and im in the process of creating a menu system. I have my main menu but i want to be able to select an option that takes me onto another menu. I have tried doing this with the case statement with no luck so far. Wondering if it... (3 Replies)
Discussion started by: RAFC_99
3 Replies

9. Shell Programming and Scripting

(sed) parsing insert statement column that crosses multiple lines

I have a file with a set of insert statements some of which have a single column value that crosses multiple lines causing the statement to fail in sql*plue. Can someone help me with a sed script to replace the new lines with chr(10)? here is an example: insert into mytable(id, field1, field2)... (3 Replies)
Discussion started by: jjordan
3 Replies
Login or Register to Ask a Question