On Wed, Feb 16, 2022 at 02:53:43PM +0100, Léa Gris wrote:
> Le 16/02/2022 à 13:43, Greg Wooledge écrivait :
> > text=$(cat /tmp/foo.txt; printf x)
> > text=${text%x}
> 
> or read -r -d '' text </tmp/foo.txt
> 
> witch saves a sub-shell

You forgot IFS= there.  Without that, it'll strip leading/trailing IFS
whitespace.

You also get a non-zero exit status from read when you use your approach,
which will cause the script to die immediately if the author is using
set -e.  While some of us may consider that a benefit (breaking more
set -e scripts raises awareness of how utterly horrible set -e is),
there are still some misguided souls out there who might not see it as
helpful just yet.

Reply via email to