Home » Infrastructure » Unix » Bash Shell Question
Bash Shell Question [message #98083] Wed, 28 January 2004 06:18 Go to next message
MM
Messages: 27
Registered: July 2002
Junior Member
Hi,

How do i pad 0's to a particular display from bash shell program. I am trying to display time in my output when i am doing it if it is 1:00 clock it diplays as 1:1:59 but i want it to be 01:01:59.
Thanks in advance

MM
Re: Bash Shell Question [message #98089 is a reply to message #98083] Thu, 05 February 2004 10:08 Go to previous message
Frank Naude
Messages: 4566
Registered: April 1998
Senior Member
Hi,

You can try something like this:

DATE='1:1:59'   
echo "OLD DATE=[$DATE]"   
HH=`echo $DATE | cut -d':' -f1`   
MI=`echo $DATE | cut -d':' -f2`   
SS=`echo $DATE | cut -d':' -f3`   
if [ "$HH" -lt "10" ]; then   
   HH="0$HH"   
fi   
if [ "$MI" -lt "10" ]; then   
   MI="0$MI"   
fi   
if [ "$SS" -lt "10" ]; then   
   SS="0$SS"   
fi   
echo "NEW DATE=[$HH:$MI:$SS]"


The output should look like this:

OLD DATE=[1:1:59] 
NEW DATE=[01:01:59]


Best regards.

Frank
Previous Topic: Directories in Unix reg. Oracle Financial Applications
Next Topic: How would I pass database column values to a UNIX shell script
Goto Forum:
  


Current Time: Sat Jan 16 12:22:34 CST 2021