- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: shell script help
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
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
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
07-05-2011 03:21 AM
07-05-2011 03:21 AM
shell script help
i want to compare two values in shell script .
example-
ca=50
pa=45
if [ $ca -gt $pa ]
i need output greater value . how to print the vaule after the if statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2011 03:46 AM
07-05-2011 03:46 AM
Re: shell script help
if [ $ca -gt $pa ]
then
echo $ca
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2011 04:45 AM - edited 07-05-2011 04:48 AM
07-05-2011 04:45 AM - edited 07-05-2011 04:48 AM
Re: shell script help
if [ $ca -gt $pa ]
then
echo $ca
elif [ $pa -gt $ca ]
then
echo $pa
else
echo "They are equal"
fi
(Sorry Hakki) :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2011 04:49 AM
07-05-2011 04:49 AM
Re: shell script help
Danke ! :smileyvery-happy:
I missed the half part of code..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2011 04:58 AM
07-05-2011 04:58 AM
Re: shell script help
Hi:
Since you only want the greater value, or if they are equal, merely that value, you could use:
# [ ${ca} -gt ${pa} ] && echo ${ca} || echo ${pa}
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2011 08:18 AM
07-05-2011 08:18 AM
Re: shell script help
If you are using a real shell you can use C style expressions:
if (( ca > pa )); then
echo $ca
else
echo $pa
fi
This prints the maximum of the two.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2011 07:25 AM
07-06-2011 07:25 AM
Re: shell script help
hi every one thanks for you reply
Dennis,
i user your script , it working fine . please tell how to print the greater value in one text file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2011 07:27 AM
07-06-2011 07:27 AM
Re: shell script help
i use your script , it is working fine. please tell how to print the greater value in one text file
because i need output value through mail, so i plan to send mailx command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2011 09:19 AM
07-06-2011 09:19 AM
Re: shell script help
Starting with Dennis' script, and noting that nothing will print if the values are equal, this might work:
if (( ca > pa )); then
echo $ca
else
echo $pa
fi > max.txt
mailx -s "max values" mail_address_here < max.txt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2011 09:28 AM
07-06-2011 09:28 AM
Re: shell script help
And if you don't plan to send much text to your message:
if (( ca > pa )); then
echo $ca
else
echo $pa
fi | mailx -s "max values" mail_address_here
>noting that nothing will print if the values are equal:
The above fragment always prints a value.