Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I don't want this:

echo "9"

Rather I need this, with e.g.: 4 spaces before it:


So if I try it with 10:


then it will just have 3 spaces before it. How can I format my output this way?

share|improve this question
3 spaces before 10 and 5 spaces before 9? Is there some reason to it, just per-number whitespace or a mistake? – rozcietrzewiacz Nov 4 '11 at 10:22
up vote 6 down vote accepted
$ alias MAGICK="printf '%5s\n'"
share|improve this answer

You should use printf if you wish to format the output.

In your example above, you could use1:

printf "\t%s\n" "9"

Where \t is a tabspace, %s is the string your wish to print and \n is a newline.

Many shells have their own version of printf - check your documentation for details.

[1] Note: I am not entirely clear from your question what it is you are trying to accomplish...

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.