2

I have been having a hard time figuring out how a specific line of bash script works. If anyone could break down how exactly this printf statement works it would be greatly appreciated.

printf "%${SPACES}s{FNAME}\n" " "

Where SPACES is a number and FNAME is the basename of a file or directory. More detail the better.

1 Answer 1

3

Is SPACE=5 then printf is equivalent to:

printf "%5s{FNAME}\n" " "

Which gives this output:

     {FNAME}
12345

i.e. 5 spaces and literal string {FNAME}

Any number between % and s is being used for space padding before actual string.

Sign up to request clarification or add additional context in comments.

2 Comments

Im still confused on the purpose of %10 and the s before {FNAME}
Yes I have added explanation in my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.