- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- error in shell script code..ksh
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
04-19-2007 10:08 PM
04-19-2007 10:08 PM
I calculated variable with bc and if I do echo $g I get: 167.500
I would like to do check for variable $g
in case it has value: 167.500 assign 168 to variable $h..or in case it has value 165.000 assign 165 to variable $h..here is what I did so far:
in=$1
a=`echo "$in/5"|bc`
b=`expr $a + 1`
g=`echo "(($b * 123) / 100)+1" | bc`
if [ $g==*000 ]
then
h=`echo "(($b * 123) / 100)" | bc`
else
h=`echo "(($b * 123) / 100)+1" | bc`
fi
value $h should be one that I look for..
any help would be helpfull..
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2007 11:19 PM
04-19-2007 11:19 PM
Re: error in shell script code..ksh
the syntax you are using is not correct.
>>
if [ $g==*000 ]
then
<<
You could use a 'case', but if you want a simple rounding to integer of
$i*1.23/5
my suggestion is:
i=$1
h=$(print $i | awk '{printf("%.0f\n",$1*1.23/5)}')
print $h
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2007 11:43 PM
04-19-2007 11:43 PM
Re: error in shell script code..ksh
-------
in case it has value: 167.500 assign 168 to variable $h..or in case it has value 165.000 assign 165 to variable $h
-----------
how( and what do u mean by above) u r going to achive above by using
-------------------
if [ $g==*000 ]
then
h=`echo "(($b * 123) / 100)" | bc`
else
h=`echo "(($b * 123) / 100)+1" | bc`
fi
------------------------
I think u have to round the figure to next integer (eg. 16.500 to 17 and 16.49 to 16)
is it this u want?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2007 12:10 AM
04-20-2007 12:10 AM
Re: error in shell script code..ksh
# in this U enter $1
a=`echo "$1/5"|bc`
b=`expr $a + 1`
c=`echo "$b*5"|bc`
g=`echo "(($b * 123) / 100)+1" | bc`
# so by calculating g goes if statement...
if [ $g==*000 ]
then
h=`echo "(($b * 123) / 100)" | bc`
else
h=`echo "(($b * 123) / 100)+1" | bc`
fi
# this means if for example $g is 167.500 value of h will be:
h=`echo "(($b * 123) / 100)+1" | bc`
and if value od $g is 156.000 vale of h will be:
h=`echo "(($b * 123) / 100)" | bc`
or more examples:
is g is 14.145 h will be:
h=`echo "(($b * 123) / 100)+1" | bc`
or if g is 45.000 h will be:
h=`echo "(($b * 123) / 100)" | bc`
my problem is in syntax of if statement in this:
if [ $g==*000 ]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2007 12:18 AM
04-20-2007 12:18 AM
Re: error in shell script code..ksh
so as it says rounding will be:
(eg. 16.500 to 17 and 16.49 to 17 again)
16.000 will be rounded to 16!..
I know specific rounding..
It is just problem with if stat.to recognise last 3 digits..
//if last 3 digits are 0 if is true:
if [ $g==*000 ] #but this does not work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2007 12:19 AM
04-20-2007 12:19 AM
Re: error in shell script code..ksh
if you insist on such a construct:
...
case $g in
*000) # if part
;;
## possibly wanted:
#*[024]00) # elif round to floor
#;;
#*[68]00) # elif round to ceiling
#;;
*) # else part
;;
esac
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2007 12:27 AM
04-20-2007 12:27 AM
Re: error in shell script code..ksh
thank U veryyy much
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2007 12:30 AM
04-20-2007 12:30 AM
Re: error in shell script code..ksh
to come back to my first solution:
Really easy for checks (modify the formula as required, if I guessed wrong):
awk '{printf("%.0f\n",$1*1.23/5)}'
Now enter you input values (stdin) and the calculated values you see on stdout.
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2007 12:37 AM
04-20-2007 12:37 AM
Re: error in shell script code..ksh
problem is he does never go in *000) check..even is $g is 123.000
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2007 01:05 AM
04-20-2007 01:05 AM
Re: error in shell script code..ksh
12.000 rounded: 12
12.043 rounded: 13
23.999 rounded: 24
etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2007 01:15 AM
04-20-2007 01:15 AM
Re: error in shell script code..ksh
then I suggest do look at the value from an integer point of view:
awk '{printf("%d\n",$1*1.23/5)}'
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2007 01:25 AM
04-20-2007 01:25 AM
Re: error in shell script code..ksh
after that we can deal with rounding..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2007 01:26 AM
04-20-2007 01:26 AM
SolutionI did not notice, that you want to round up - my last solution just drops the fractional part.
So better add .5 and use usual rounding:
awk '{printf("%.0f\n",$1*1.23/5+0.5)}'
BTW: the case solution does not work due to the format your '$g' has: I don't see any fractional output in
print $g
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2007 01:52 AM
04-20-2007 01:52 AM
Re: error in shell script code..ksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2007 01:53 AM
04-20-2007 01:53 AM