redirection if command help please


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting redirection if command help please
# 1  
Old 12-30-2010
redirection if command help please

Code:
#!/bin/bash

    clear
    echo "Hello $USER"
    echo "Do you wish to run this network configuration script [Y/N]?"
    read option
    
    
    if($option == 'Y' || 'y' )
    then
                    
        echo " auto eth0
        iface eth0 inet static
        address 192.168.1.161
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255
        gateway 192.168.1.206:7926
        
        auto eth0:1
        iface eth0:1 inet static
        address 146.192.161.112
        netmask 255.255.255.0
        network 146.192.161.0
        broadcast 146.192.161.255
        gateway 146.192.161.254
        
        auto eth0:2
        iface eth0:2 inet static
        address 10.10.121.116
        netmask 255.255.255.0
        network 10.10.121.0
        broadcast 10.10.121.255
        gateway 10.10.121.211:3162 " >> /etc/network/interfaces
    fi
    
    if($option != "Y" || "y")
    then
        echo "Okay! Bye!"
    fi

^^^^^ that is my entire script....all i am attempting is:

IF user input is Y or y then add text to file indicated......else if user option is not Y or y then print message and exit.

I get the following error message after running the script:
Code:
Hello administrator
Do you wish to run this network configuration script [Y/N]?
y
./net script2.sh: line 9: y: command not found
./net script2.sh: line 9: y: command not found
./net script2.sh: line 37: y: command not found
./net script2.sh: line 37: y: command not found

this output is given with every input, although the error does change, but, only where it will replace the y with the letter inputted....can anyone help please???

thanks in advance

wez


Moderator's Comments:
Mod Comment Please use code tags when posting data and code samples, thank you.

Last edited by Franklin52; 12-30-2010 at 10:34 AM..
# 2  
Old 12-30-2010
if syntax is not correct. it should be:
Code:
if [[ "$option" = "Y" || "$option" = "y" ]]

and
Code:
if [[ "$option" != "Y" && "$option" != "y" ]]

# 3  
Old 12-30-2010
Or:

Code:
case "${option}" in
           "Y"|"y")     # Do the task
                            echo " auto eth0
                            .... et cetera ....
                            gateway 10.10.121.211:3162 " >> /etc/network/interfaces
           ;;
           *)            # Exit
           echo "Okay! Bye!"
           ;;
esac

# 4  
Old 01-03-2011
thanks

thanks for the replies however none of the fixes work, i am still recieveing the same errors. any other ideas please guys?

thanks again
# 5  
Old 01-03-2011
Please post the entire modified script, the exact command you're executing and the exact output.
# 6  
Old 01-03-2011
Check what comparison operators bash has. is it = or == or eq or -eq. Check the syntax in if line as well.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command output redirection to file issues

Hi, I have a peculiar issue w.r.t redirecting the command output to a file when using loop. I am redirecting command output to same file in a series of if condition statements, but if one block of if condition statement writes the log to the file , the subsequent block of if condition... (7 Replies)
Discussion started by: ananan
7 Replies

2. UNIX for Dummies Questions & Answers

Redirection of file input to command

Hello, I'm new to Unix (working with OS X 10.8.5) and therefore at the beginning of my adventure. If I ask something stupid, then this is not intentional, but simple nescience. :rolleyes: I have a problem with the redirection of text file content to echo. I was experimenting with redirection... (6 Replies)
Discussion started by: pseudo
6 Replies

3. Shell Programming and Scripting

Command output redirection in script not working

I need to count the number of lines in a .txt file and put it in a variable. I am using the following code #!/bin/bash count = $(wc -l "some file.txt" | awk '{print$1}') echo $count It is giving the following error. line3: count: command not foundWhat am I doing wrong here? :confused: (7 Replies)
Discussion started by: haritha.gorijav
7 Replies

4. UNIX and Linux Applications

output redirection command

Dear All, ./waf --run scratch/myfirst > log.out 2>&1 The above is a command line to redirect the output to a file called log.out. what is the 2>&1 part for ? Thank you (2 Replies)
Discussion started by: knowledgeSeeker
2 Replies

5. Shell Programming and Scripting

I/O redirection

Hello everyone,I'm reading a book and there's code fragment: exec 3>&1 ls -l 2>&1 >&3 3>&- | grep bad 3>&- exec 3>&- It says that the red part of that code does not close fd 3 but the green does close the fd 3.I can't understand that.....Why?Any predicate will be appreciated.:) (18 Replies)
Discussion started by: homeboy
18 Replies

6. Shell Programming and Scripting

Help with tar --append command output redirection

I am using tar command to append daily database backups on tape. "tar --append " command help me to do this. But tar --append command does not produce any output on stdout if it succeed. I want the output for that appended command to a log file. This log file should contain only the name of the... (0 Replies)
Discussion started by: pganguly46
0 Replies

7. UNIX for Dummies Questions & Answers

Help with Redirection

Hi Guys, I m new to UNIX and new to this forum. Was wondering if someone can help me understand redirection (standard input output pipeline etc) for starters, not too sure what this would mean who | sort > sortedfile | pr | lp im starting to understand common commands but when throwing... (2 Replies)
Discussion started by: jmack123
2 Replies

8. Shell Programming and Scripting

nohup command o/p redirection

Hi I am using nohup command in script(say nohup ls- ltr > somefile 2>&1 & ). I dont want any kind of output to be displayed on screen. When i tried the above nohup it still gives me some out put on screen like 2991 Done >somefile 2>&1 Please you let me know what is... (3 Replies)
Discussion started by: ammu
3 Replies

9. Shell Programming and Scripting

echo command and file I/O Redirection

I have a colon-delimited text file of names, addresses and phone numbers. I am trying to write a script that can add additional entries and then sort it alphabetical by last name and resave it to the original file. I am using C shell to script. This is the section of my script that I wish to... (8 Replies)
Discussion started by: userix
8 Replies

10. Filesystems, Disks and Memory

Unix command redirection

Hi all,, Is there any way to redirect the command o/p directaly to a memory location instead of redirecting it to the file?? (1 Reply)
Discussion started by: swap007
1 Replies
Login or Register to Ask a Question