What to do>! and >>! do in tcsh

In the usual bash redirection > redirecting standard output to a file, rewriting when it exists, and >> redirecting standard output to a file, adding when it exists.

In the tcsh (c shell) script, I found the used operators >! >>! . What do these operators do? tcsh also has > and >> operators, so what's the difference?

+12
redirect tcsh
Jul 20 '11 at 13:00
source share
2 answers

The tcsh redirect! the symbol means overwriting an existing file, even if noclobber installed.

In other words, if noclobber is installed, then:

  • cmd > file will write stdout for the file if the file does not exist
  • cmd > file will fail if file exists
  • cmd >> file will add stdout to the file if the file exists
  • cmd >> file will fail if the file does not exist
  • cmd >! file cmd >! file will write stdout to a file, overwriting any existing file
  • cmd >>! file cmd >>! file will add stdout to the file, creating the file if it does not already exist

If noclobber is not installed, then! has no effect:

  • cmd > file will write stdout to the file, overwriting any existing file
  • cmd >> file will add stdout to the file
  • cmd >! file cmd >! file will write stdout to a file, overwriting any existing file
  • cmd >>! file cmd >>! file will add stdout to the file
+28
Jul 20 2018-11-21T00:
source share

An exclamation mark suppresses the type of file that is written in some cases.

To quote the tcsh man page:

If the noclobber shell variable is set, then the file must not exist or be a special character file (for example, a terminal or '/ dev / null) or an error result. This helps prevent accidental file destruction. In this case '! forms can be used to suppress this verification.

+3
Jul 20 2018-11-21T00:
source share



All Articles