How to represent formatted printf using echo in bash

142 Views Asked by At

What is a command that produces the same output as formatted printf in bash

1

There are 1 best solutions below

6
On BEST ANSWER

If the echo on your System supporting -ne then you can define a function like...

$ puts(){(echo -ne "sometext ${1}\t ${2}\n ${3}\n")}
$ puts hello world bye
sometext hello   world
 bye

( Typed in a bash )

For looping through the List of Arguments this is possible...

puts(){
for string in ${@}; do
 echo -ne ${string}
done
}

Than you can do...

puts 0 1 "\n" 3 "\t" 4 5 6 "\n" 7 8 9 "\n"