Nested ifs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Nested ifs
# 1  
Old 06-23-2012
Error Nested ifs

hi I keep getting an error with this nested if statement and am getting the error unexpected end of file, can anyone help me as to why this wont execute?

Code:
 
#!/bin/bash
#script to check wether the -i -v statements run correctly
removeFile ()
        {
        mv $1 $HOME/deleted
        }
#Function to imitate verbose
verbose ()
        {
        echo  " removed $1 "
i_option=0
v_option=0
r_option=0
while getopts :ivrR option
do
        case $option in
                i) i_option=1 ;;
                v) v_option=1 ;;
                r|R) r_option=1 ;;
                *) echo "invalid option" ;;
        esac
shift $(( $OPTIND -1 ))
done

if [[ $i_option -eq 1 && $v_option -eq 1 && $r_option -eq 0 ]]
then
        if [ -f $1 ]
        then
                if [ -s $1 ]
                then
                        read -p "rm: remove regular file '$1'?" choice
                                if [[ $choice = Y || $choice = y ]]
                                then
                                        removeFile $1
                                        verbose $1
                                else
                                        exit 1
                                fi
                elif ! [ -s $1 ]
                then
                        read -p "rm: remove regular empty file '$1'?" choice1
                                if ! [[ $choice1 = Y || $choice1 = y ]]
                                then
                                        removeFile $1
                                        verbose $1
                                else
                                        exit 1
                                fi
                fi
        elif [ -d $1 ]
        then
                echo "rm: cannot remove '$1': Is a directoy"
        else
                echo "No such a file or directory"
        fi
fi

# 2  
Old 06-23-2012
verbose()
{
your code here
}
# 3  
Old 06-23-2012
Error thanks

Thank you very much that seems to work. One problem however is that even when I select N when given the choice to delete or not it still deletes the file. any ideas as to why?
# 4  
Old 06-23-2012
Code:
verbose ${@}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remote while IFS

Hello masters of scripting, I've been working to develop some basic monitoring scripts. I have solved one problem, but want to know how to solve the other. I have a script that runs locally to create an output file with the Linux system kernel paramters, preceeded by the system name: ... (2 Replies)
Discussion started by: LinuxRacr
2 Replies

2. UNIX for Dummies Questions & Answers

How to use nested ifs in unix?

how to use nested ifs in unix (1 Reply)
Discussion started by: pratima.kumari
1 Replies

3. Shell Programming and Scripting

While loop and IFS?

Hi, while ; do echo "Please enter " read enter yyyy=${enter:0:4} mm=${enter:5:2} dd=${enter:8:2} result=`validateDate $yyyy $mm $dd` When does the loop keeping repeating till?? till 1 is equal to 1? what does this mean "${enter:0:4}" .The 0 and 4 part?? ... (3 Replies)
Discussion started by: sid22
3 Replies

4. Shell Programming and Scripting

regarding IFS=

hi i am a learner can some explain "export IFS=$(echo "\n\t\a")" i am not able to understand the functionality please help thanks Satya (1 Reply)
Discussion started by: Satyak
1 Replies

5. Shell Programming and Scripting

Shell nested ifs

Hi can someone tell me whats wrong with the following: #!/bin/sh file1=$1 file2=$2 if then if then echo "File 1 is" $file1 echo "File 2 is" $file2 cp $file1 $file2 echo "Copy complete!" else echo "ERROR: File does not exist!" ... (8 Replies)
Discussion started by: philmetz
8 Replies

6. UNIX for Dummies Questions & Answers

Help on IFS command!

Hi! I am working in korn shell. I want to reset the dimiliter for the set command to "|" but instead of a command prompt return I am getting something as below After issuing the command I am getting this....as if the shell is expecting something else. Can anybody suggest what's the problem. ... (2 Replies)
Discussion started by: udiptya
2 Replies

7. Shell Programming and Scripting

Trouble with Nested Ifs

What I thought was going to be very simple has turned out to be really lame, and so I come to you for help. mountedon=`df -k /synctest | awk 'NR == 2 {print $1}'` if then # mount /pupcl06 mountedon=`df -k /synctest | awk 'NR == 2 {print $1}'` if then mailx -s... (2 Replies)
Discussion started by: ProFiction
2 Replies

8. Shell Programming and Scripting

problem with IFS

hi, :) I set IFS=":" But when i try to echo $IFS,i am not getting any thing on the screen escept a blank line. any help pls. cheers RRK (11 Replies)
Discussion started by: ravi raj kumar
11 Replies

9. UNIX for Dummies Questions & Answers

IFS variable

How can I set the value for IFS variable (2 Replies)
Discussion started by: mahabunta
2 Replies

10. UNIX for Dummies Questions & Answers

the IFS variable

Hi all, Ok os heres my situation. I have created a database style program that stores a persons info (name,address,phone number etc.) in a file ("database"). after i read in all the values above, i assign them to a line variable: line="$name^$address^$phonenum" >> phonebuk as you can see... (1 Reply)
Discussion started by: djt0506
1 Replies
Login or Register to Ask a Question