Difference between printf and echo in Bash

后端 未结 4 1223
悲哀的现实
悲哀的现实 2021-01-21 08:45
$ printf \'apple\' | wc -m
       5
$ echo \'apple\' | wc -m
       6

Why printf prints 5 and echo prints 6 characters?

4条回答
  •  遥遥无期
    2021-01-21 09:35

    Here is the difference ..

    $printf 'abcd'
    abcd$ echo 'abcd'
    abcd
    $
    

    As you can see the additional char is newline \n

提交回复
热议问题