Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

So I don't want this:

echo "9"
9

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

MAGICK "9"
    9

So if I try it with 10:

MAGICK "10"
   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

2 Answers 2

up vote 6 down vote accepted
$ alias MAGICK="printf '%5s\n'"
$ MAGICK 10
   10
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

 
discard

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.