Please note, that [] && cmd
के रूप में ही नहीं
हैif .. fi
construction.
Sometimes its behaviour its pretty similar and you can use
[] && cmd
instead of if .. fi
. But
only sometimes. If you have more then one command to execute if
condition or you need if .. else .. fi
be careful and
whatch the logic.
कुछ उदाहरण:
[ -z "$VAR" ] && ls file || echo wiiii
के रूप में ही नहीं है
if [ -z $VAR ] ; then
ls file
else
echo wiii
fi
क्योंकि अगर ls
विफल हो जाएगा, तो echo
निष्पादित किया जाएगा जो <�कोड> यदि के साथ नहीं होगा
एक और उदाहरण:
[ -z "$VAR" ] && ls file && echo wiii
के रूप में ही नहीं है
if [ -z "$VAR" ] ; then
ls file
echo $wiii
fi
हालांकि यह निर्माण एक ही कार्य करेगा
[ -z "$VAR" ] && { ls file ; echo wiii ; }
कृपया ध्यान दें कि गूंज के बाद ;
महत्वपूर्ण है और
उसमें होना चाहिए।
तो ऊपर दिए गए कथन को हम कह सकते हैं
[] && cmd
== if first command is successful
then execute the next one
if .. fi
== if condition (which may be the test
command as well) then execute command(s)
तो [
और [[
के बीच पोर्टेबिलिटी के लिए
[
का उपयोग करें।
if
is POSIX compatible. So if you have to choose
between [
and if
choose looking at your
task and expected behaviour.