- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Shell scripting
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
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
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-21-2001 07:21 AM
тАО08-21-2001 07:21 AM
In my scrip, I have the following loop :
# while true
# do
# typeset -i txt
# echo " Enter a value for $2 (min:${5} - max:${6}) [$CurrValue] : \c"
# read txt 2>/dev/null
# if [[ $? -eq 0 ]]
# then
# if [[ $txt = "" ]]
# then
# txt=$CurrValue
# fi
# if [[ $txt -ge $5 && $txt -le $6 ]]
# then
# break
# fi
# fi
# done
with
$2 : Variable name
$5 : Minimum value
$6 : Maximum value
$CurrVal : Actual variable value
Typeset -i --> force to enter an integer
--> BUT if the user want the default value and only press ENTER, the value of $txt is 0 ! What's the best way to avoid this?
Many Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2001 07:33 AM
тАО08-21-2001 07:33 AM
Re: Shell scripting
Try changing the line:
if [[ $txt = "" ]]
to:
if [[ $txt = "" ]] || [[ $txt -eq 0 ]]
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2001 07:43 AM
тАО08-21-2001 07:43 AM
Re: Shell scripting
As txt is defined as integer type you can just check
if [ $txt -eq 0 ]; then
.
.
fi
...BPK...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2001 03:42 PM
тАО08-21-2001 03:42 PM
Re: Shell scripting
I do recommend quoting variable EVRYWHERE!
so it yould be like
if [ "$txt" = "" ]
and you will be out of trouble...
HTH,
Wodisch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2001 04:14 PM
тАО08-21-2001 04:14 PM
Solutionecho "enter your value"
read x
if [ "$x" = "" ]
then
echo you did not type in anything
else
echo "$x + 1" |bc 2>&1 |grep syntax > /dev/null 2>&1
if [ $? = 0 ]
then
echo "You typed in some characters"
exit
fi
fi
#once it is confirmed that the iniput is not a character
#we check it for zero
if [ $x = 0 ]
then
echo "Sorry zero is not allowed"
exit
fi
#Then we can do whatever we want to do with x as it is
do_whatever_you_wanna_do_with_$x
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2001 09:00 AM
тАО08-22-2001 09:00 AM
Re: Shell scripting
The typeset's problem is that he gives 0 if you do not enter anything. If 0 is a correct value (the minimum one for instance), it is not easy :-)))
Better not assign to integer
Bye and thanks to all of you