Re:How to write idempotent Bash scripts
by gabrielblack on Sunday July 07, 2019 @02:47PM
(#20376927)
"echo -n " is useless, is sufficient:
> example.txt
without prepending the echo command. This will create an empty file or it will truncate an existent file. The touch command could be preferable to preserve the content, if needed.
Re:How to write idempotent Bash scripts
by gabrielblack on Monday July 08, 2019 @03:39AM
(#20380697)
P.S.
>> example.txt
this one (with a double > ) could replace touch in this application case: it's less readable but more efficient.
If a file has a line ending in it, is it truly empty?
The -n flag keeps echo from emitting a line ending.
doh! I read it as \n, but then that's for other languages, so i was just all sorts of not paying attention
I used a distro in recent memory where `echo -n foo` really produced `-n foo`.
The workaround was `printf "%s" foo`.
Ironically article calls "This is an easy one"