Saturday, December 8, 2018

When to use square brackets [ ] also know as test in shell scripting?

test is more frequently called as [ . It is normally a shell builtin ( which means shell itself will interpret [ as test)

$ type [
[ is a shell builtin

$which [
/usr/bin/[

$ls -l /usr/bin/[
-rwxr-xr-x 1 root root 41544 Dec 4 2017 /ur/bin/[

$ls -l /usr/bin/test
-rwxr-xr-x 1 root root 37400 Dec 4 2017 /usr/bin/test

Test is mostly invoked with if and while statements, it is also the reason you will come into difficulties if you create  a program called test and try to run it. As this shell builtin will be called instead of your program.

***

No comments:

Post a Comment