0

I execute a script like ./script.sh with one parameter: ./script.sh on.

This tells a script to turn my light off or on depending on the value of the parameter.

I use this case statement for this:

#!/bin/bash
case "$1" in
on) sudo something
    ;;
off) sudo something
    ;;
esac
exit 0

Now, I want to give another parameter, for the location of my lights. It is not of importance now how this works with the light switching, I want to make another case statement in the on) and off) cases.

I tried this, but that does not work:

#!/bin/bash
case "$1" in
on) 
    case "$2" in
    kitchen) sudo something
             ;;
    garage) sudo something
            ;;
    esac
    ;;
off)
    case "$2" in
    kitchen) sudo something
             ;;
    garage) sudo something
            ;;
    esac
    ;;
esac
exit 0

I am completely not familiar with UNIX, I manage to follow some tutorial but that's it. Any help is appreciated! Also, a whole other case structure, like checking two parameteres at the same time would be great, anything that works helps! :)

Also, I am sorry if this is the wrong StackExchange community, please let me know and I'll move it to another!

P.S. I am using Raspbian (on Raspberry Pi)

2
  • 1
    I just ran your above script under Debian replacing the sudo with echo and it appeared to work for me. Are any errors reported when you run the script, or is it just not producing the output your expecting?
    – JonathanS
    Mar 8, 2015 at 16:40
  • I think I am having some trouble with the rights etc. I have some time later this evening and I'll let you know which errors I get
    – B_s
    Mar 8, 2015 at 16:42

0

You must log in to answer this question.

Browse other questions tagged .