Re: помогите упростить условие bash
30.11.2013 00:48, Oleksandr Gavenko пишет: А POSIX то не дочитали...: http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_09_05_01 2.9.5 Function Definition Command ... Exit Status The exit status of a function definition shall be zero if the function was declared successfully; otherwise, it shall be greater than zero. The exit status of a function invocation shall be the exit status of the last command executed by the function. Вот тебе и чтение манов на ночь ) Спасибо. Закоммитил. -- -- Best regards, Vladimir Skubriev -- To UNSUBSCRIBE, email to debian-russian-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/529c0a7c.9010...@skubriev.ru
Re: помогите упростить условие bash
On 2013-11-29, dimas wrote: check_rebuild_status() { grep -q recovery /proc/mdstat } тогда уж сразу греп, нафиг такая функция? Я знаю что вы шутите, и все же SPOT[1], модульность, повторное использование, самодокументируемость... [1] http://en.wikipedia.org/wiki/Single_Point_of_Truth -- Best regards! -- To UNSUBSCRIBE, email to debian-russian-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/8738mep445@gavenkoa.example.com
Re: помогите упростить условие bash
On 2013-11-29, Vasily Ivanov wrote: On 29.11.13 0934 (+0400), Vladimir Skubriev wrote: check_rebuild_status(){ if [ $(grep recovery /proc/mdstat -c) -ne 0 ]; then return 0 else return 1 fi } Чтобы было более элегантно. check_rebuild_status(){ grep -q recovery /proc/mdstat return $? } check_rebuild_status() { grep -q recovery /proc/mdstat } -q, --quiet, --silent Quiet; do not write anything to standard output. Exit immediately with zero status if any match is found, even if an error was detected. Also see the -s or --no-messages option. (-q is specified by POSIX.) А POSIX то не дочитали...: http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_09_05_01 2.9.5 Function Definition Command ... Exit Status The exit status of a function definition shall be zero if the function was declared successfully; otherwise, it shall be greater than zero. The exit status of a function invocation shall be the exit status of the last command executed by the function. -- Best regards! -- To UNSUBSCRIBE, email to debian-russian-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/87pppjdjdq@gavenkoa.example.com
Re: помогите упростить условие bash
check_rebuild_status() { grep -q recovery /proc/mdstat } тогда уж сразу греп, нафиг такая функция? -- To UNSUBSCRIBE, email to debian-russian-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/20131130014448.208d7...@ulf.tvoe.tv
помогите упростить условие bash
check_rebuild_status(){ if [ $(grep recovery /proc/mdstat -c) -ne 0 ]; then return 0 else return 1 fi } Чтобы было более элегантно. -- -- Best regards, Vladimir Skubriev -- To UNSUBSCRIBE, email to debian-russian-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/5298274c.6020...@skubriev.ru
Re: помогите упростить условие bash
On 29.11.13 0934 (+0400), Vladimir Skubriev wrote: check_rebuild_status(){ if [ $(grep recovery /proc/mdstat -c) -ne 0 ]; then return 0 else return 1 fi } Чтобы было более элегантно. check_rebuild_status(){ grep -q recovery /proc/mdstat return $? } -q, --quiet, --silent Quiet; do not write anything to standard output. Exit immediately with zero status if any match is found, even if an error was detected. Also see the -s or --no-messages option. (-q is specified by POSIX.) -- To UNSUBSCRIBE, email to debian-russian-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/20131129055001.ga7...@roadwarrior.8p8c.net