5

I am trying to learn commands in Bash and came across these examples. Why does adding a '.' prevent the sequence number from getting printed?

This is the behaviour I want, but I couldn't find anything on the man page.

printf "%.sI" $(seq 10)

IIIIIIIIII

printf "%sI" $(seq 10)

1I2I3I4I5I6I7I8I9I10I

1 Answer 1

15

printf allows you to specify a precision which is applicable even for strings:

Relevant statements from the printf(3) manpage:

An optional precision, in the form of a period ('.') followed by an optional decimal digit string.

If the precision is given as just '.', or the precision is negative, the precision is taken to be zero.

This gives ... the maximum number of characters to be printed from a string for s and S conversions.

So printf '%.s' is equivalent to printf '%.0s', which suppresses the output from the subsequent string parameter.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .