SORU
6 NİSAN 2011, ÇARŞAMBA


Fallthrough ile dava açmak mı?

Bash fallthrough durumlarda (büyük küçük harf duyarlı ise en iyi) ile anahtarı doğru sözdizimi için deyim arıyorum. PHP gibi program istiyorum:

switch($c) {
    case 1:
        do_this();
        break;
     case 2:
     case 3:
        do_what_you_are_supposed_to_do();
        break;
     default:
        do_nothing(); 
}

Bash aynı istiyorum:

case "$C" in
    "1")
        do_this()
        ;;
    "2")
    "3")
        do_what_you_are_supposed_to_do()
        ;;
    *)
        do_nothing();
        ;; 
esac

Bu şekilde çalışmıyor: fonksiyonu do_what_you_are_supposed_to_do() ateş zaman $C 2 VEYA 3.

CEVAP
6 NİSAN 2011, ÇARŞAMBA


Dikey çubuk "veya".

case "$C" in
"1")
    do_this()
    ;;
"2" | "3")
    do_what_you_are_supposed_to_do()
    ;;
*)
    do_nothing()
    ;;
esac

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Feel The Electricity!

    Feel The Ele

    20 ŞUBAT 2010
  • MrExcite96

    MrExcite96

    17 ŞUBAT 2011
  • Tube Time

    Tube Time

    14 Mayıs 2013