# redirection if command help please

**URL:** <https://community.unix.com/t/redirection-if-command-help-please/279988>\
**Category:** Shell Programming and Scripting\
**Created:** [December 30, 2010, 9:25am UTC](https://community.unix.com/t/redirection-if-command-help-please/279988 "2010-12-30T09:25:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![wezzyb](https://community.unix.com/letter_avatar/wezzyb/32/5_5575768a8748004e209b776fc1b2916d.png) [@wezzyb](https://community.unix.com/u/wezzyb)\
**Post date:** [December 30, 2010, 9:25am UTC](https://community.unix.com/t/redirection-if-command-help-please/279988/1 "2010-12-30T09:25:13Z")

</div>

```nohighlight
#!/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:

```nohighlight
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

---

<div class="post-metadata">

**Author:** ![anurag.singh](https://community.unix.com/letter_avatar/anurag.singh/32/5_5575768a8748004e209b776fc1b2916d.png) [@anurag.singh](https://community.unix.com/u/anurag.singh)\
**Post date:** [December 30, 2010, 9:38am UTC](https://community.unix.com/t/redirection-if-command-help-please/279988/2 "2010-12-30T09:38:30Z")

</div>

if syntax is not correct. it should be:

```nohighlight
if [["$option" = "Y" || "$option" = "y"]]

```

and

```nohighlight
if [["$option" != "Y" && "$option" != "y"]]

```

---

<div class="post-metadata">

**Author:** ![methyl](https://community.unix.com/letter_avatar/methyl/32/5_5575768a8748004e209b776fc1b2916d.png) [@methyl](https://community.unix.com/u/methyl)\
**Post date:** [December 30, 2010, 10:13am UTC](https://community.unix.com/t/redirection-if-command-help-please/279988/3 "2010-12-30T10:13:51Z")

</div>

Or:

```nohighlight
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

```

---

<div class="post-metadata">

**Author:** ![wezzyb](https://community.unix.com/letter_avatar/wezzyb/32/5_5575768a8748004e209b776fc1b2916d.png) [@wezzyb](https://community.unix.com/u/wezzyb)\
**Post date:** [January 3, 2011, 5:15am UTC](https://community.unix.com/t/redirection-if-command-help-please/279988/4 "2011-01-03T05:15:10Z")

</div>

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

thanks again

---

<div class="post-metadata">

**Author:** ![radoulov](https://community.unix.com/user_avatar/community.unix.com/radoulov/32/489_2.png) [@radoulov](https://community.unix.com/u/radoulov)\
**Post date:** [January 3, 2011, 5:36am UTC](https://community.unix.com/t/redirection-if-command-help-please/279988/5 "2011-01-03T05:36:43Z")

</div>

Please post the entire modified script, the exact command you're executing and the exact output.

---

<div class="post-metadata">

**Author:** ![sudhakarn](https://community.unix.com/letter_avatar/sudhakarn/32/5_5575768a8748004e209b776fc1b2916d.png) [@sudhakarn](https://community.unix.com/u/sudhakarn)\
**Post date:** [January 3, 2011, 5:39am UTC](https://community.unix.com/t/redirection-if-command-help-please/279988/6 "2011-01-03T05:39:49Z")

</div>

Check what comparison operators bash has. is it = or == or eq or -eq. Check the syntax in if line as well.
