bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

leading zeros ignored by perl, ksh. not bash


From: Maik.Liedtke
Subject: leading zeros ignored by perl, ksh. not bash
Date: Wed, 23 Jul 2014 07:20:01 +0000

hello,

to change our scripts from ksh to bash we have problems with vars and leading 
zeros.
how we can declare hrs and min?
or can we disable the automatic change from decimal to octal?


leading zeros ignored by perl, ksh. not bash
cannnot declare vars hrs and min as decimal only


address@hidden:/home/user> ./mltest.pl
TIME = 08:09
hrs=08 | min=09 | locmin=489


address@hidden:/home/user> ./mltest.ksh
TIME=08:09
hrs=8 | min=9 | locmin=489


address@hidden:/home/user> ./mltest.sh
TIME=08:09
./mltest.sh: line 9: 08: value too great for base (error token is "08")
./mltest.sh: line 10: 09: value too great for base (error token is "09")
hrs= | min= | locmin=0


code (mltest.sh)

#!/bin/bash

declare -i hrs min locmin

TIME="08:09"
echo "TIME=$TIME"

hrs=$(echo ${TIME}|cut -f1 -d ':')
min=$(echo ${TIME}|cut -f2 -d ':')
#hrs=$(echo ${TIME}|cut -f1 -d ':'|bc -l)             # workaround 1: ok
#min=$(echo ${TIME}|cut -f2 -d ':'|bc -l)             # workaround 1: ok
###hrs=$(echo ${TIME}|cut -f1 -d ':'|sed "s/^0*//")   # workaround 2: ok
###min=$(echo ${TIME}|cut -f2 -d ':'|sed "s/^0*//")   # workaround 2: ok

locmin=hrs*60+min

echo "hrs=$hrs | min=$min | locmin=$locmin"



Kind regards / Cordialement / Mit freundlichen Grüssen

Maik Liedtke * System Consultant * ASP * Asset Arena * SunGard * Solmsstr. 18 * 
60486 Frankfurt am Main, Deutschland
Tel +49 69 70768-118 * Mobile +49 176 11110-118  * Fax +49 69 70768-599 * 
mailto:address@hidden  * www.sungard.com/assetarena<http://www.sungard.com/>
Hotline ASP Support
Tel +49 69 70768-111 * Fax +49 69 70768-112 * 
mailto:address@hidden<mailto:address@hidden>

CONFIDENTIALITY: This e-mail (including any attachments) may contain 
confidential, proprietary and privileged information, and unauthorized 
disclosure or use is prohibited.
If you receive this e-mail in error, please notify the sender and delete this 
e-mail from your system.
SunGard Systeme GmbH * Registered: Frankfurt am Main, Handelsregister Frankfurt 
HRB 56839 * Geschäftsführer: Dean B. Gluyas, Christian U. Haas, Henry Morton 
Miller Jr., Victoria E. Silbey



reply via email to

[Prev in Thread] Current Thread [Next in Thread]