[SLUG] zero-padding in bash

From: Eben King (eben1@tampabay.rr.com)
Date: Thu Oct 21 2004 - 19:37:25 EDT


I'm trying to get zero-padded output, e.g., 3 -> 003, 57 -> 057, 792 ->
792. {,pd}ksh could do this years ago, as

typeset -Z3 varname
varname=3
echo $varname # or "print $varname"

and the output is "003". How do I do it in bash? Or do I need to keep on
using pdksh for all my padding needs?

-- 
-eben    ebQenW1@EtaRmpTabYayU.rIr.OcoPm    home.tampabay.rr.com/hactar
GEMINI:  Your birthday party will be ruined once again by your explosive
flatulence. Your love life will run into trouble when your fiancee hurls a
javelin through your chest.  -- Weird Al, _Your Horoscope for Today_

----------------------------------------------------------------------- This list is provided as an unmoderated internet service by Networked Knowledge Systems (NKS). Views and opinions expressed in messages posted are those of the author and do not necessarily reflect the official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 20:01:00 EDT