Re: Displaying octal numbers in bash

2003-09-25 Thread Roger Oberholtzer
While on the octal front, anyone know how to get the date command, when
used with format specifiers, NOT to prefix a number with a zero? I use it
in a Makefile to put a time stamp in a C program, but the leading 0 forces
the compiler to think it is octal. So, this month '09' is not accepted.
Offending are month, hour and minute. day and year have a format without
leading 0.

e.g.;

date +%m

gives '09'.


On Wed, 24 Sep 2003 21:00:08 -0400
Joel Hammer [EMAIL PROTECTED] wrote:

 I understand that bash will do arithmetic in octal if you prefix the
 constant with 0. So:
 a=05
 b=017
 c=$((a*b))
 echo $c
 yields
 75
 This is the correct answer, but it is in decimals, not octals.
 Is there a way to make echo display octal?
 Thanks, 
 Joel



-- 
++···+
· Roger Oberholtzer  ·   E-mail: [EMAIL PROTECTED]·
· OPQ Systems AB ·  WWW: http://www.opq.se/  ·
· Erik Dahlbergsgatan 41-43  ·Phone: Int + 46 8   314223 ·
· 115 34 Stockholm   ·   Mobile: Int + 46 733 621657 ·
· Sweden ·  Fax: Int + 46 8   302602 ·
++···+

___
Linux-users mailing list
[EMAIL PROTECTED]
Unsubscribe/Suspend/Etc - http://www.linux-sxs.org/mailman/listinfo/linux-users


Re: Displaying octal numbers in bash

2003-09-25 Thread David A. Bandel
On Thu, 25 Sep 2003 08:40:02 +0200
Roger Oberholtzer [EMAIL PROTECTED] wrote:

 While on the octal front, anyone know how to get the date command,
 when used with format specifiers, NOT to prefix a number with a zero?
 I use it in a Makefile to put a time stamp in a C program, but the
 leading 0 forces the compiler to think it is octal. So, this month
 '09' is not accepted. Offending are month, hour and minute. day and
 year have a format without leading 0.
 
 e.g.;
 
   date +%m
 
 gives '09'.

from the man page:

   By  default, date pads numeric fields with zeroes.  GNU date
recognizes
   the following modifiers between `%' and a numeric directive.

  `-' (hyphen) do not pad the field `_' (underscore) pad the
field
  with spaces


Ciao,

David A. Bandel
-- 
Focus on the dream, not the competition.
Nemesis Racing Team motto
GPG key autoresponder:  mailto:[EMAIL PROTECTED]


pgp0.pgp
Description: PGP signature
___
Linux-users mailing list
[EMAIL PROTECTED]
Unsubscribe/Suspend/Etc - http://www.linux-sxs.org/mailman/listinfo/linux-users


Re: Displaying octal numbers in bash

2003-09-25 Thread Joel Hammer
This seems more work that it should be.

I did solve my problem with bc, but, there must be an easy way to get
bash to display octal.

Joel
On Wed, Sep 24, 2003 at 06:35:18PM -0700, Tom Wekell wrote:
 
 Joel Hammer wrote:
  I understand that bash will do arithmetic in octal if you prefix the
  constant with 0. So:
  a=05
  b=017
  c=$((a*b))
  echo $c
  yields
  75
  This is the correct answer, but it is in decimals, not octals.
  Is there a way to make echo display octal?
  Thanks, 
  Joel
  
 
 More arithmetic?
 
 echo $((8#$c*1)) gives 61
 
___
Linux-users mailing list
[EMAIL PROTECTED]
Unsubscribe/Suspend/Etc - http://www.linux-sxs.org/mailman/listinfo/linux-users


Displaying octal numbers in bash

2003-09-24 Thread Joel Hammer
I understand that bash will do arithmetic in octal if you prefix the
constant with 0. So:
a=05
b=017
c=$((a*b))
echo $c
yields
75
This is the correct answer, but it is in decimals, not octals.
Is there a way to make echo display octal?
Thanks, 
Joel

___
Linux-users mailing list
[EMAIL PROTECTED]
Unsubscribe/Suspend/Etc - http://www.linux-sxs.org/mailman/listinfo/linux-users


Re: Displaying octal numbers in bash

2003-09-24 Thread Tom Wekell
Joel Hammer wrote:
I understand that bash will do arithmetic in octal if you prefix the
constant with 0. So:
a=05
b=017
c=$((a*b))
echo $c
yields
75
This is the correct answer, but it is in decimals, not octals.
Is there a way to make echo display octal?
Thanks, 
Joel

More arithmetic?

echo $((8#$c*1)) gives 61

Tom Wekell

___
Linux-users mailing list
[EMAIL PROTECTED]
Unsubscribe/Suspend/Etc - http://www.linux-sxs.org/mailman/listinfo/linux-users