Welcome to the Linux Foundation Forum!

printf & echo

Options

what r the diferences b/w printf and echo cmd.........

is use of printf better than echo? how...........

Comments

  • vonbiber
    vonbiber Posts: 28
    Options
    well, it depends on what you want to do
    if you want just a basic display, echo is enough
    printf allows you to display with formatting features. If you're
    familiar with c, it's similar to c's printf
    I'll give you some examples

    # i=5

    1. echo
    # echo $i
    5
    #

    2. printf
    # printf $i
    5#printf "$i\n"
    5
    #

    # printf "%02d\n" $i
    05
    #

    As you must have noticed with printf the
    newline character '\n' is not automatically added as in
    echo

Categories

Upcoming Training