linuxbashprintfechoformatted-text

How to represent formatted printf using echo in bash


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


Solution

  • 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"