- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: ksh script needing an interger cmd. line arg
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
08-31-2001 10:27 AM
08-31-2001 10:27 AM
./my_script A B C
C needs to be >=0 and an integer
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2001 10:33 AM
08-31-2001 10:33 AM
Re: ksh script needing an interger cmd. line arg
if (( $c >= 0 ))
then
fi
Paula
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2001 10:46 AM
08-31-2001 10:46 AM
Re: ksh script needing an interger cmd. line arg
you could do something simple like
if [ $3 -gt 0 ]
then
echo "3rd argument greater then 0"
fi
-Ramesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2001 10:47 AM
08-31-2001 10:47 AM
Re: ksh script needing an interger cmd. line arg
for >=0 change it to
if [ $3 -ge 0 ]
then
echo "3rd argument greater then 0"
fi
-Ramesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2001 10:53 AM
08-31-2001 10:53 AM
Re: ksh script needing an interger cmd. line arg
echo "$3 + 1 " |bc 2>&1 |grep syntax > /dev/null
if [ $? = 0 ]
then
echo "Your C is some character"
exit
fi
#Once the above is passed, it means it's an integer. Now I will check to see if it is > 0.
if [ $3 -gt 0 ]
then
echo "C should be greater than 0"
exit 1
fi
...code...
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2001 10:57 AM
08-31-2001 10:57 AM
Re: ksh script needing an interger cmd. line arg
yaada..yadaa..yadaaa..
...
if [ $3 -le 0 ]
then
echo "Arg 3 should be greater than 0"
exit
fi
...code...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2001 12:03 PM
08-31-2001 12:03 PM
SolutionHere's one somewhat rigorous way:
#!/usr/bin/sh
#
typeset X=$3
#
[ -z "$X" ] && { echo "no argument provided";exit 2; }
#
[ `expr $X : '[0-9]*'` -ne `expr $X : '.*'` ] && { echo "not a positive integer"
;exit 1; }
#
[ "$X" -le 0 ] && { echo "zero not allowed";exit 1; }
#
echo "OK"
exit 0
#
#.end.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2001 12:15 PM
08-31-2001 12:15 PM
Re: ksh script needing an interger cmd. line arg
As I am still learning scripting why use "gt" instead of >= ?
Paula
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2001 12:20 PM
08-31-2001 12:20 PM
Re: ksh script needing an interger cmd. line arg
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2001 12:44 PM
08-31-2001 12:44 PM
Re: ksh script needing an interger cmd. line arg
sridhar, your solution does not work reliably for all possible input
james, yours works and is more compact than my crude attempt with grep and regular expressions, but i was hoping there was something built into the shell/test like "if (( -I $3 ))" where I would be that magical test on a number
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2001 01:05 PM
08-31-2001 01:05 PM
Re: ksh script needing an interger cmd. line arg
Interesting. Did you have any instance where it couldn't get to work?. That will help me rectify my logic.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2001 01:22 PM
08-31-2001 01:22 PM
Re: ksh script needing an interger cmd. line arg
echo "f + 5" | bc 2>&1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2001 02:13 PM
08-31-2001 02:13 PM
Re: ksh script needing an interger cmd. line arg
....
echo "${3}.1 + 1 " |bc 2>&1 |grep syntax > /dev/null
............
if [ $? = 0 ]
....
Thanks for letting me know.
-Sri