test कमांड
test command computer के लिए एक yes-or-no quiz question जैसा है, जैसे 'क्या यह file वहां है?'। यह quietly pass या fail कहकर जवाब देता है, और script उस आधार पर decide करती है कि क्या करना है।
In this page:
Syntax
test expression
[ expression ]
The test Command
test expression (जो [ expression ] के रूप में भी लिखा जाता है) एक condition evaluate करता है और इसके अनुसार इसका exit status set करता है, conditions लिखने का classic POSIX तरीका बनाते हुए।
[ ] को हर token के आस-पास और brackets खुद के आस-पास spaces चाहिए। यह ज़्यादा feature-rich [[ ]] से पहले आता है और POSIX-portable scripts के लिए अब भी उपयोग होता है।
Warning:
एक space missing होना, जैसे
[$a -eq $b], एक syntax error है — [ असल में एक command है जिसे argument separators के रूप में spaces चाहिए।उदाहरण: The test Command
#!/bin/bash
a=5
if test "$a" -eq 5; then
echo "a equals 5 (using test)"
fi
if [ "$a" -eq 5 ]; then
echo "a equals 5 (using [ ])"
fi
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- Brackets के आस-पास spaces भूल जाना, जैसे
[$a -eq 1], जो एक error है। - Tests में variables को unquoted छोड़ना, इसलिए एक empty value
unary operator expectedदेती है। [ ]में==और=को inconsistently उपयोग करना, क्योंकि=portable वाला है।
🔒
Chapter Quiz — Complete all 10 topics to unlock
0/10 topics done
Complete these topics first: