← Back to context

Comment by 1vuio0pswjnm7

1 day ago

Whats the advantage of the colon for the truncation example

  >file1 >file2

versus

  : >file1 >file2

I've done quick and dirty, interactive truncation like the former for many years, no colon. But I would not use it in scripts

According to https://www.in-ulm.de/~mascheck/bourne/ SVR4 (1989) had a bug when using this method in a for or while loop and this bug showed up in a SunOS 5 variant, too

Apparently, early in the shell's evolution, : was used as a comment marker before # was added

Single quotes could be used to prevent undesired behaviour

   : echo output 1>&2

   : `echo output 1>&2`

   : '`echo output 1>&2`'

System III (1981) also had a bug when using : as a substitute for true

   if false;then :;fi

returned 1 instead of 0