Questions tagged [test]

This is about the Unix utility "test," also invoked as "[", or its shell syntax [[ … ]] variant. For questions about testing software and setups, use the "testing" tag.

The test, or [, utility is used in the shell and shell scripts to evaluate conditions, usually for conditional execution of code.

Ksh, bash and zsh also have a dedicated syntax [[ … ]].

Further reading

360 questions
9
votes
3 answers

What does `[ EXPRESSION ], [ ] and [OPTION` mean in `man test`?

Examining man test, I see that under synopsis for test are the possibilities test EXPRESSION and test. What does [ EXPRESSION ], [ ] and [OPTION mean below ? Why are the brackets empty and why does [OPTION miss a bracket ? Can someone interpret…
Shuzheng
  • 4,411
2
votes
2 answers

How to correctly test file's extension in if statement?

Just an illustration: first cd /usr/lib and run for x in $(ls);do if [ "$x" == "*.a" ];then echo $x;fi;done What I want to do is to select files with extension .a and print them. I know there are much simpler way of doing this, but that is not…
user15964
  • 713
1
vote
0 answers

difference between non-builtin 'test' and '['

I am aware that bash builtin test and [ commands are exactly the same, but what about /usr/bin/test and /usr/bin/[? I guess those two are not exactly the same as then one would be just a symlink pointing to another? $ ls -l /usr/bin/test -rwxr-xr-x…
Martin
  • 7,516
1
vote
3 answers

Where can I find the list of [[ ]] options?

like [[ -s file ]] [[ -z string ]] preferably on the web. I looked on the ldp site but couldn't find them The man page (man [) is helpful but I am looking for a more compact list.
-1
votes
1 answer

-n Vs !(exclamation mark) behaves differently with test command

#!/bin/bash declare -A numMap numMap[1]=1 #case-one if ! [[ ${numMap[1]} ]];then echo "case-one: the key 1 for numMap array is not set" fi #case-two if [[ -n ${numMap[1]} ]]; then echo "case-two: the key 1 for numMap array is not set" fi I…
user93868
-2
votes
2 answers

Need to delete logs from different locations using shell script

Need to delete logs with different name from different locations and need to delete the logs more than 5 days. Ex: /abc/bcd/fgh/log/log1.txt /abc/bcd/fgh/test/log2.log /test/urc/mhg/event.log /hjy/jghd/qwer/nbcvd/eda.log
palani
  • 1
-3
votes
1 answer

"[ - abc=10 ]" vs "[ – abc = 10 ]"

How are they different? I am using the [ command. I know we need a space after [ and before ], and that the test command is equivalent. But I can't find any information about the difference between the expressions [ abc=10 ] and [ abc = 10 ]
Maxfield
  • 161