Welcome to the new Linux Foundation Forum!

enhancement of echo

what r the drawbacks of echo command? can u plz suggest some enhancements in echo command.

Comments

  • Hum... interesting question. Echo is a simple program, with plenty of options already (man echo for details ^_^).

    So I guess it is quite complete already. I never encountered snaggs with echo.
  • atreyuatreyu Posts: 216
    gr8linux wrote:
    what r the drawbacks of echo command? can u plz suggest some enhancements in echo command.
    well, i don't know if it is a drawback, per se, but there is a built-in function in the shell (I use bash) call echo. This sometimes confuses me when I think I'm calling the echo utility from gnu coreutils.

    I personally prefer to use printf, b/c I like the greater flexibility it has in string formatting, etc.
  • gr8linuxgr8linux Posts: 26

    I personally prefer to use printf, b/c I like the greater flexibility it has in string formatting, etc.

    can u plz gv me some examples of why u prefer printf and how it is more flexible than echo.......i m looking for that. i wanna know what uses r missing in echo.
  • atreyuatreyu Posts: 216
    gr8linux wrote:

    I personally prefer to use printf, b/c I like the greater flexibility it has in string formatting, etc.

    can u plz gv me some examples of why u prefer printf and how it is more flexible than echo.......i m looking for that. i wanna know what uses r missing in echo.

    make some nice columns in output:
    printf "%-20s%s\\n" meh blah
    printf "%-20s%s\\n" foo bar
    

    round up to a whole number:
    printf '%0.f\\n' 1.5
    

    convert hex to decimal:
    printf '%d\\n' 0x100000000
    
Sign In or Register to comment.