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

 SSD VPS Hosting - Vpsie.com
 Mo.nitor.me
 Ivorde forum
 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

Posted on: 24 Jan 2008
Author: mandrei
Section: Server Operating Systems | Problems and Solutions
Views: 530
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
» How to allow access to su to root on FreeBSD
» How to change Environment Variable $MAIL on FreeBSD box
» How to prevent accidental file overwrites from output redirection




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.
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 16th, 2012 - 17: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 - 09:46
Testing for an existing socket is with '-S'.

   Latest topics on the forum:
 
   Most viewed articles:
How to copy a mysql database using mysqldump - 9376 views
How to change a user's password in AIX with the output from ECHO command - 8635 views
FreeBSD: Add/remove an additional IP alias - 5609 views
Qmail relay to smarthost: How to route all mail to a smarthost - 3929 views
Print queues in AIX 5L - How to list print queues in AIX - 2884 views

   Latest 10 articles:
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
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
How to rename files/directories to uppercase/lowercase character names - 17 Jun 2008
How to convert lower case to upper case letters in a shell script/command - 17 Jun 2008
Unix,Linux,FreeBSD - How to rename a list of files, replacing spaces inside their names - 12 Jun 2008
How to change a user's password in AIX with the output from ECHO command - 21 May 2008


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



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