help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

function that prints each argument on a new line


From: lisa-asket
Subject: function that prints each argument on a new line
Date: Tue, 6 Jul 2021 13:40:46 +0200 (CEST)

Would like to have a function that prints a number of lines by passing them as 
arguments. 

Each string to be printed it a separate line.



But have to compose the `frmt`  variable to `printf` appropriately depending on 
the number of strings being

passed to the function.





Have tried te repeat the string "%s\n" by the number of function arguments.  
But cannot get things as I wish.





pfb ()

{  

  local -r frmt=$(printf '%s\n' $(seq $#))
  printf "frmt: $frmt"
  printf $frmt "$@"
  local -r frmt="%s\n%s\n"
  printf $frmt "$@"
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]