Page 1 of 1

About -f -d -s -z -x... options? [SOLVED]

Posted: Sun 06 Sep 2015, 12:18
by Argolance
Bonjour,

Code: Select all

[ -f "$HOME/Startup/network_tray" ] && echo File exists

Code: Select all

[ -d "$HOME/Startup" ] && echo Directory exists

Code: Select all

VAR=""
[ -z "$VAR" ] && echo Variable is empty???
What is the -x option used for?
Maybe to know if the file is executable or not :roll:

Code: Select all

 [ -x "$HOME/.xinitrc"  ] && echo File is executable???
Is there other options of this type it would be interesting to know? Where to find a complete list?

Cordialement.

Posted: Sun 06 Sep 2015, 12:20
by step
-x is for executable bit set
man test

Posted: Sun 06 Sep 2015, 13:17
by Argolance
... Exactly what I was looking for: but how would I have guessed it was this 'test' command that is behind, while it is not specified inside the code line? Very useful indeed..
Thanks a lot!

Posted: Sun 06 Sep 2015, 14:16
by some1
Advanced Bash-Scripting Guide:
7.2. File test operators
http://tldp.org/LDP/abs/html/fto.html

Don maintains an updated pet of the guide.

Posted: Sun 06 Sep 2015, 16:21
by step
Argolance wrote:... Exactly what I was looking for: but how would I have guessed it was this 'test' command that is behind, while it is not specified inside the code line? Very useful indeed..
Thanks a lot!
In early unix systems the command '[' was a symlink to the command 'test'. Then shells evolved to include test as a built-in, and reinforced the [ ] and [[ ]] syntax. I believe [ ] works in all shells, while [[ ]] is specific to bash and maybe some other advanced shells.
You can still find older scripts that use 'test':
if test a = b; then
same as
if [ a = b ]; then
Mind that there are spaces around [ and ]

Posted: Sun 06 Sep 2015, 18:19
by Argolance
All is just and perfect! 8)