Dynamic Case statement in korn shell



  • A co-worker asked me a question about the possility of using "dynamic case statements" (marked bold): 

    case (( $(AANTAL_LISTENERS) != 2 )) in
                    [[ -n ${WRONG_LISTENER} ]] )
                                            echo "func_wrong_list"
                                            ;;
                    [[ -z ${LISTENER1} ]] )
                                            echo "lsnrctl start" ${LISTENER1}
                                            ;;
                    [[ -z ${LISTENER2} ]] )
                                            echo "lsnrctl start" ${LISTENER2}
                                            ;;
                    [[ -z ${LISTENER1} -a ${LISTENER2} ]] )
                                            echo "lsnrctl start ${LISTENER1} && lsnrctl start ${LISTENER2}"
                                            ;;
     
    esac

     

    Spot the wtf's.... (the echo statements are for debugging I think)



  • What the hell is it with flow control that confuses people?



  • @Lingerance said:

    What the hell is it with flow control that confuses people?
     

    Wasn't it Joel Spolsky who said this differentiates developers from the rest of the world? (ie the ability to grasp flow control). It's one of the first questions you should test in a technical interview.



  • "case word in" not "case test in"
    Using case where an if statement should be used.
    ksh case statement doesn't do fall-through.
    When using ksh build in test "[[" you should use a logical and not "-a" in order to test multiple conditions "&&" now the last test is for LISTENER1 being zero, LISTENER2 'file exists'

    Aditionally: if ${LISTENER1} or ${LISTENER2} is empty then start the listener named in the empty variable...uhm 

     



  • @b_redeker said:

    Wasn't it Joel Spolsky who said this differentiates developers from the rest of the world? (ie the ability to grasp flow control). It's one of the first questions you should test in a technical interview.

    I thought it was pointers.



  • @blakeyrat said:

    @b_redeker said:
    Wasn't it Joel Spolsky who said this differentiates developers from the rest of the world? (ie the ability to grasp flow control). It's one of the first questions you should test in a technical interview.

    I thought it was pointers.


    Well he said something that might of been some importance to someone sometime.



  • @OzPeter said:

    @blakeyrat said:
    @b_redeker said:
    Wasn't it Joel Spolsky who said this differentiates developers from the rest of the world? (ie the ability to grasp flow control). It's one of the first questions you should test in a technical interview.

    I thought it was pointers.


    Well he said something that might of been some importance to someone sometime.
    [citation needed]



  • @blakeyrat said:

    @b_redeker said:
    Wasn't it Joel Spolsky who said this differentiates developers from the rest of the world? (ie the ability to grasp flow control). It's one of the first questions you should test in a technical interview.

    I thought it was pointers.

     Am I the only one who thinks blakeyrat's avatar looks a little bit like a Predator (from the movie, you know..)?



  • @pbean said:

    @blakeyrat said:

    @b_redeker said:
    Wasn't it Joel Spolsky who said this differentiates developers from the rest of the world? (ie the ability to grasp flow control). It's one of the first questions you should test in a technical interview.

    I thought it was pointers.

     Am I the only one who thinks blakeyrat's avatar looks a little bit like a Predator (from the movie, you know..)?

    Probably. It's a pangolin.


  • Discourse touched me in a no-no place

    @bstorer said:

    @OzPeter said:
    Well [Joel Spolsky] said something that might of been some importance to someone sometime.
    [citation needed]
    http://www.joelonsoftware.com/articles/Wrong.html? I found that to be one of his more saner articles.



  • No, that's C++. In less masochistic languages, pointers are easy. In fact, in Java, pointers are SO easy that some programmers use them without even knowing it!*

     

     

    *These are the bad programmers who don't understand what Java is doing.



  •  I prefer the less-popular slipknot shell.


Log in to reply