Operating System - HP-UX
1838655 Members
3271 Online
110128 Solutions
New Discussion

List of if-then-else conditions

 
SOLVED
Go to solution
Hunki
Super Advisor

List of if-then-else conditions

Does somebody have a link for a list of conditions of if-then-else statements. Something like what "-a" , "-z" etc are for.

thanks,
hunki
4 REPLIES 4
Dave Hutton
Honored Contributor
Solution

Re: List of if-then-else conditions

man sh-posix (if you are using posix) more then what I list below:


Conditional Expressions
A conditional expression is used with the [[ compound command to test
attributes of files and to compare strings. Word splitting and file
name generation are not performed on the words between [[ and ]].
(See also the test special command.) Each expression can be
constructed from one or more of the following unary or binary
expressions:

-a file True, if file exists.
-b file True, if file exists and is a block special
file.
-c file True, if file exists and is a character
special file.
-d file True, if file exists and is a directory.
-e file True, if file exists.
-f file True, if file exists and is an ordinary file.
-g file True, if file exists and has its setgid bit
set.
-h file True, if file exists and is a symbolic link.
-k file True, if file exists and has its sticky bit

Hunki
Super Advisor

Re: List of if-then-else conditions

thanks dave!
James R. Ferguson
Acclaimed Contributor

Re: List of if-then-else conditions

Hi Hunki:

# man test

...i.e. the manpages for 'test'...

Regards!

...JRF...
Reshma Malusare
Trusted Contributor

Re: List of if-then-else conditions

Hi Hunki,
The if statement allows you to execute one or several commands if a certain condition exists. The syntax is:

if command-line
then conditional_cmd_line1
[else conditional_cmd_line2 ]
fi

if checks for command_line true. (true means command_line returns 0.) If true, conditional_cmd_line1 executes; if not, conditional_cmd_line2 executes.
-h symbolic link for file.
-k file with sticky bit
-x tests for an executable file
-a file exists
-b block special file exists.
-c Chracter special file.
-d directory.
-f ordinary file.
-g setgid bit set for file.
-h symbolic link for file.
-k file True, if file exists and has its sticky bit