- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: If statement
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2004 02:06 AM
09-05-2004 02:06 AM
for example .
if [-s ...]
a manual for the option after if (-s ,-f ,-d).
THANKS
Rgds.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2004 02:14 AM
09-05-2004 02:14 AM
Solutionhttp://goforit.unk.edu/unix/ostart.htm
Module 3 : shell scripts, and you will see on the "Shell conditionnal tests" :
Test Meaning:
!= not equal
= equal
-eq equal
-gt greater than
-ge greater than or equal
-lt less than
-le less than or equal
! logic negation
-a logical and
-o logical or
-r file true if the file exists and is readable
-w file true if the file exists and is writable
-x file true if the file exists and is executable
-s file true if the file exists and its size > 0
-d file true if the file is a directory
-f file true if the file is an ordinary file
-t filed true if the file descriptor is associated with a terminal
-n str true if the length of str is > 0
-z str true if the length of str is zero
Olivier.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2004 02:18 AM
09-05-2004 02:18 AM
Re: If statement
$man 1 sh-posix
search for 'Conditional Expressions'
you will find them there
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2004 02:27 AM
09-05-2004 02:27 AM
Re: If statement
http://users.sdsc.edu/~steube/Bshell/
Olivier.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2004 07:23 AM
09-05-2004 07:23 AM
Re: If statement
# man test
That will give you some examples of the test conditions that you can use with the if/fi statement.
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2004 04:03 PM
09-05-2004 04:03 PM
Re: If statement
if [[
then
< operation's >
fi
or
if [
then
< operation's >
fi
where we have need a format as,
if
then
< operation's >
fi
if
then
fi
we have to use if / elif / else as,
if [[
then
action1
elif [[
then
action2
elif [[
then
action3
else
action4
fi
-f file True if file exists and is a regular file.
-d file True if file exists and is a directory.
-s file True if file exists and has a size greater than zero.
We can encorporate on script as,
#!/usr/bin/ksh
# Debugging mode
set -x
########################
echo "Enter input"
read input
if [[ -f $input ]]
then
echo "$input is a regular file"
elif [[ -d $input ]]
then
echo "$input is a directory"
elif [[ -s $input ]]
then
echo "$input is a file and exists with size greater than zero `ll $PWD/$input`"
else
echo "$input is not needed to check for -d / -f / -s option"
exit 1
fi
# Normal exit
exit 0
We can use another method simply as,
to check is there a file then,
[[ -f
Example:
[[ -f /stand/vmunix ]] && echo "System file is there"
Regards
-Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2004 04:10 PM
09-05-2004 04:10 PM
Re: If statement
regrads
SK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2004 05:50 PM
09-05-2004 05:50 PM
Re: If statement
So indeed 'man test' will give you info.
But 'test' is also a 'shell built-in', so you may also have a look at the shell's manpage.
JP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2004 06:16 PM
09-05-2004 06:16 PM
Re: If statement
Thanks all.