If I type echo hello, my terminal looks like this:My-Computer:~ user$ echo hellohelloMy-Computer:~ user$ But if I have a function like thisstringen () { cat /dev/urandom | env LC_CTYPE=C tr -cd 'a-Z-A-z-0-9' | head -c $1 ; }It looks like thisMy-Computer:~ user$ stringen 18^\k6JPWVIUdEiudcWSMy-Computer:~ user$ See that it doesn't print it in a new line? Same thing when using printf vs echo. How can I do so that my functions makes new lines like this? I thought that the ; would take care of this but obviously not.For example, this returns what I wantvariable=$(stringen 18)echo $variableIs it something with echo?
How to print new lines at the end of functions?
shell;echo;newlines
Neither, cat, tr or head adds a newline character (urandom could, but it's random so I wouldn't trust it). You have to manually insert the new line, with either a printf '\n' at the end of your function, or an echo.BTW, some shells do add it, like zsh, to prevent these kinds of situations.