bash - What is the difference between "echo" and "echo -n"? -


the manual page on terminal echo -n following:

 -n    not print trailing newline character.  may        achieved appending `\c' end of string, done        ibcs2 compatible systems.  note option        effect of `\c' implementation-defined in ieee std 1003.1-2001        (``posix.1'') amended cor. 1-2002.  applications aiming        maximum portability encouraged use printf(1)        suppress newline character.   shells may provide builtin echo command similar or iden-  tical utility.  notably, builtin echo in sh(1) not  accept -n option.  consult builtin(1) manual page. 

when try generate md5 hash by:

echo "password" | md5 

it returns 286755fad04869ca523320acce0dc6a4

when do

echo -n "password" 

it returns value online md5 generators return: 5f4dcc3b5aa765d61d8327deb882cf99

what difference option -n do? don't understand entry in terminal.

when echo "password" | md5, echo adds newline string hashed, i.e. password\n. when add -n switch, doesn't, characters password hashed.

better use printf, tell without needing switches:

printf 'password' | md5 

for cases 'password' isn't literal string, should use format specifier instead:

printf '%s' "$pass" | md5 

this means escape characters within password (e.g. \n, \t) aren't interpreted printf , printed literally.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -