Software >> OS >> Unix >> Shell >> bash >> printf examples

 

 

S/N Task Example
  print left justified

printf "%-10s" "hello"

hello

  print right justified

printf "%10s\n" "hello"

     hello

  print middle justified  
  pass the width as argument

printf "%*f\n" 10 10

 10.000000

 

  pass width and precision as argument

printf "%*.*f\n" 10 2 10

     10.00