0

I have a piece of code like this:

printf "%.s  "  $(seq 1 $count)

It actually belongs to an else condition and its job is to print out whitespaces $count times..

It works fine if I enter a string like this:

printf "%.shelloworld  "  $(seq 1 $count)

but not when i just put in whitespaces.

Any work arounds?

COOLBEANS
  • 729
  • 3
  • 13
  • 31

1 Answers1

1

Works for me:

# printf "%.s  "  $(seq 1 10) | hexdump -C
00000000  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000010  20 20 20 20                                       |    |

Is this the exact command that's being entered, or is there other variable substitution happening? Because the exact thing you seem to be experiencing would happen if you didn't quote a particular variable expansion:

# frm="%.s  "; printf $frm $(seq 1 10) | hexdump -C
[no output]

Whereas:

# frm="%.s  "; printf "$frm" $(seq 1 10) | hexdump -C
00000000  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000010  20 20 20 20                                       |    |
Sammitch
  • 30,782
  • 7
  • 50
  • 77