FreeBSD - Tutorials, Security
Home   Archives   Sitemap   About   Contact

Shell scripting - conditions for IF conditional function

Home NEW! Unix Forum News 100 Tips and Tricks Website Development Server Operating Systems Databases
 Ivorde.ROarrow Server Operating Systems arrowProblems and SolutionsarrowShell scripting - conditions for IF conditional function 

Article Sections

    Hello, Guest !
User name:
Password:
 
Google

 SATELLITE INTERNET
 FreeBSD Tutorials
 Linux LVM Commands
 Free Shell Accounts
 FreeBSD Project
 FreeBSD Handbook
 Advanced Bash-Scripting Guide
 The OpenBSD Project
 Distrowatch
 FreeBSD Handbook


Apache Webserver Home Page

Blog, intrebari si raspunsuri despre Leasing

Posted on: 24 Jan 2008
Author: mandrei
Section: Server Operating Systems | Problems and Solutions
Views: 275
Comments: 2 (Add)

Shell scripting - conditions for IF conditional function
shell scripting, conditional if, shell script conditions

Below there are some of the conditions used with the conditional shell scripting function: IF

▫ -d file = True if the file exists and is a directory.

▫ -b file = True if the file exists and is block special file.

▫ -c file = True if the file exists and is character special file.

▫ -k file = True if the files' "sticky" bit is set.

▫ -f file = True if the file exists and is a regular file

▫ -e file = True if the file exists.

▫ -g file = True if the file exists and the set-group-id bit is set.

▫ -L file = True if the file exists and is a symbolic link.

▫ -p file = True if the file exists and is a named pipe.

▫ -r file = True if the file exists and is readable.

▫ -s file = True if the file exists and its size is greater than zero.

▫ -s file = True if the file exists and is a socket.

▫ -t fd = True if the file descriptor is opened on a terminal.

▫ -u file = True if the file exists and its set-user-id bit is set.

▫ -w file = True if the file exists and is writable.

▫ -x file = True if the file exists and is executable.

▫ -O file = True if the file exists and is owned by the effective user id.

▫ -G file = True if the file exists and is owned by the effective group id.

▫ file1 –nt file2 = True if file1 is newer, by modification date, than file2.

▫ file1 ot file2 = True if file1 is older than file2.

▫ file1 ef file2 = True if file1 and file2 have the same device and inode numbers.

▫ -z string = True if the length of the string is 0.

▫ -n string = True if the length of the string is non-zero.

▫ string1 = string2 = True if the strings are equal.

▫ string1 != string2 = True if the strings are not equal.

▫ !expr = True if the expr evaluates to false.

▫ expr1 –a expr2 = True if both expr1 and expr2 are true.

▫ expr1 –o expr2 = True is either expr1 or expr2 is true.

Depending on the shell you're using, the syntax for this conditional function could be:
if [[ file ]] ; then...

if [ file ]; then .....

Bookmarks: Echo "Shell scripting - conditions for IF conditional function" around:
del.icio.usdiggFurlYahooMyWebGoogleBookmarksFaceBookTechnocratti
-------------------advertising-----------------

Other articles in Server Operating Systems / Problems and Solutions
» Change user shell on FreeBSD Linux and AIX
» Secure Unix shell account with auto-logout after seconds of inactivity - Idle TMOUT
» Reloading /etc/profile - how to reload Unix /etc/profile
» How to allow access to su to root on FreeBSD
» How to change Environment Variable $MAIL on FreeBSD box




Contact webmaster regarding this article
Register or Login to post your article
Hello, Guest ! You can Login or Register to www.ivorde.ro!

 Post comment:

Name:
Title:
Comment:
Please type the word you see in the image (anti-spam verification). Refresh the page if you don't understand the word.
Verification code
Allowed HTML Tags for comments:<p><strong><em><u><h1><h2><h3><h4><h5><h6><img><li>
<ol><ul><span><div><br><ins><del>

2 comment(s) to Shell scripting - conditions for IF conditional function:

1. Re: Shell scripting - conditions for IF conditional function
These have nothing to do with if by anon at January 17th, 2012 - 00:23
Actually, these have nothing to do with the if function in bash. The syntax for if is: "if ". If the return status of the command is 0, it is true, and if it's any other number it's false.

2. Re: Shell scripting - conditions for IF conditional function
-S by anon at January 25th, 2009 - 16:46
Testing for an existing socket is with '-S'.

   Latest topics on the forum:
Nginx + php-fpm setting php upload_max_filesize and other php values per vhost
Mysql> how to store select Zulu / UTC timestamp in database
Quagga ospf neighbour stuck in ExStart/DROther state
How to disable anonymous access in samba 3
"checking for libnet_build_ip in -lnet... no"+"ERROR! Libnet library not found"
CentOS Install Nemesis packet crafting tool + Libnet
Using curl to get the HTTP response from an HTTP server
Mdadm - Linux software RAID
Linux - Unable to login (and authentication succeeds) - File size limit exceeded
Linux/FreeBSD how to check ntp time synchronization
 
   Most viewed articles:
How to remove first/last character from a string using SED - 6818 views
How to clear/reset DNS cache on Windows XP / Linux - 4477 views
Reloading /etc/profile - how to reload Unix /etc/profile - 4447 views
How to calculate difference in days between two dates in MySQL - 4406 views
Set up HTTP PROXY via command line in Linux/FreeBSD - 3685 views

   Latest 10 articles:
FreeBSD - Collect installed hard disk drive information - 19 Mar 2009
Set up FTP PROXY via command line in Linux/FreeBSD - 19 Mar 2009
Set up HTTP PROXY via command line in Linux/FreeBSD - 19 Mar 2009
Qmail relay to smarthost: How to route all mail to a smarthost - 03 Feb 2009
EXIM 4 relay to smarthost: How to route all mail except local domain - 03 Feb 2009
Windows XP: print LISTEN ports and network connections using netstat - 30 Jan 2009
qmail qmail-scanner/clamav qmail-inject: fatal: qq temporary problem / clamdscan: corrupt or unknown clamd scanner error or memory/resource/perms problem - exit status 512/2 - 05 Dec 2008
How to cut out first last n characters from each file name, from a filelist - 04 Nov 2008
Mozilla Firefox3 is now released - 18 Jun 2008
How to switch lower case to upper case and upper case to lower case in a string - 17 Jun 2008


Archives
» 2007  |  June  |  October  |  November  |  December
» 2008  |  January  |  February  |  March  |  April  |  May  |  June  |  November  |  December
» 2009  |  January  |  February  |  March



Home | Archives | Sitemap | About | Contact

Designed and developed by Andrei Manescu. Optimized for Mozilla Firefox.  
Copyright 2007 Andrei Manescu
All trademarks and copyrights on this page are owned by their respective owners. Comments are owned by those who posted them.
Valid W3 Document Valid XHTML 1.0 Transitional Valid CSS! The FreeBSD Project Viewable With Any Browser