Re: [SLUG] pad a variable with spaces in bash?

From: Dylan William Hardison (dylanwh@tampabay.rr.com)
Date: Sat Feb 14 2004 - 21:30:01 EST


printf:

#!/bin/bash
foo=$(printf "%-8s" bar)
echo "a${foo}b"

Spake Eben King on Saturday, February 14, 2004 at 09:06PM -0500:
> Does anybody know how to pad a variable with spaces in bash? In {pd}ksh,
>
> .--
> | #! /bin/ksh
> | typeset -L8 foo=bar
> | echo "a${foo}b"
> '--
>
> would print
> abar b
>
> How would I do a similar thing in bash (without calling ksh -c 'typeset
> -L8 foo=bar; echo "a${foo}b"')?
>
> --
> -eben ebQenW1@EtaRmpTabYayU.rIr.OcoPm home.tampabay.rr.com/hactar
> Your pretended fear lest error might step in is like the man who
> would keep all wine out of the country lest men should be drunk.
> -- Oliver Cromwell
>
>
> -----------------------------------------------------------------------
> 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.
>

-- 
"Rise up this morning, smile with the rising sun.
Three little birds, sits by my doorstep. Singing sweet
songs, of melodies pure and true."
              -- Bob Marley, "Three Little Birds" (song)
-
GPG Fingerprint=D67D 2B75 53C6 9769 30E4  D390 239F C833 F32C F6F6
GPG KeyID=F32CF6F6
-----------------------------------------------------------------------
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 - 17:52:51 EDT