- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Conditional Expressions doubt
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
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
04-05-2004 02:22 AM
04-05-2004 02:22 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2004 02:37 AM
04-05-2004 02:37 AM
Re: Conditional Expressions doubt
what's the context?
If I look at 'test' manpage, I cannot find -L, -e and -a.
So, what's the language are you 'writing' in?
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2004 02:40 AM
04-05-2004 02:40 AM
Re: Conditional Expressions doubt
Jeff Traigle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2004 02:44 AM
04-05-2004 02:44 AM
SolutionThe best way to avoid all this confussion is to adopt the "double brackets" approach:
This version will always use the shell's internal test operator (and is thus more efficient):
if [[ $(a) -gt $(b) && -f "${MYFILE}" ]]
then
fi
This equivalent version will call the external test command:
if [ $(a) -gt $(b) -a -f "${MYFILE}" ]
then
fi
Note that the syntax is a little different in the two cases.
If you must run under the Bourne shell for portability then you should always use the test command and stay within its more limited set of operators but if you know you will always be ruunning on a Korn or POSIX shell or bash then I would favor the internal test operator.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2004 02:50 AM
04-05-2004 02:50 AM
Re: Conditional Expressions doubt
if [[ ${a} -gt ${b} && -f "${MYFILE}" ]]
then
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2004 02:50 AM
04-05-2004 02:50 AM
Re: Conditional Expressions doubt
Check this example:
"pru.sh" 17 lines, 183 characters
file="/tmp/pru/sbinsh"
if [ -a ${file} ]; then
echo "-a"
fi
if [ -e ${file} ]; then
echo "-e"
fi
if [ -h ${file} ]; then
echo "-h"
fi
if [ -L ${file} ]; then
echo "-L"
fi
# ll
total 2
-rwx------ 1 root sistemas 183 Apr 5 16:46 pru.sh
lrwxrwxrwx 1 root sistemas 8 Apr 5 16:43 sbinsh -> /sbin/sh
# ./pru.sh
-a
-e
-h
-L
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2004 02:59 AM
04-05-2004 02:59 AM
Re: Conditional Expressions doubt
sks