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

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

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

#1 Post 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.
Last edited by Argolance on Sun 06 Sep 2015, 13:18, edited 1 time in total.

step
Posts: 1349
Joined: Fri 04 May 2012, 11:20

#2 Post by step »

-x is for executable bit set
man test
[url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Fatdog64-810[/url]|[url=http://goo.gl/hqZtiB]+Packages[/url]|[url=http://goo.gl/6dbEzT]Kodi[/url]|[url=http://goo.gl/JQC4Vz]gtkmenuplus[/url]

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#3 Post 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!

some1
Posts: 117
Joined: Thu 17 Jan 2013, 11:07

#4 Post 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.

step
Posts: 1349
Joined: Fri 04 May 2012, 11:20

#5 Post 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 ]
[url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Fatdog64-810[/url]|[url=http://goo.gl/hqZtiB]+Packages[/url]|[url=http://goo.gl/6dbEzT]Kodi[/url]|[url=http://goo.gl/JQC4Vz]gtkmenuplus[/url]

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#6 Post by Argolance »

All is just and perfect! 8)

Post Reply