CSnewb
CSnewb

Reputation: 147

Bash printf confusion

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.

Upvotes: 2

Views: 235

Answers (1)

anubhava
anubhava

Reputation: 785058

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.

Upvotes: 3

Related Questions