In normal bash redirection >
redirecting standard output to a file, overwriting when it exists and >>
redirecting standard output to a file, appending when it exists.
In a tcsh (c shell) script I found the operators >!
>>!
being used. What do this operators do? tcsh does also have the >
and >>
operators, so what is the difference?
It is a command language interpreter usable both as an interactive login shell and a shell script command processor. It includes a command-line editor, programmable word completion, spelling correction, a history mechanism, job control, and a C-like syntax. You can invoke the shell by typing an explicit tcsh command.
This is the same as &> . From the bash manpage: Redirecting Standard Output and Standard Error This construct allows both the standard output (file descriptor 1) and the standard error output (file descriptor 2) to be redirected to the file whose name is the expansion of word.
Tcsh is an enhanced version of the csh. It behaves exactly like csh but includes some additional utilities such as command line editing and filename/command completion. Tcsh is a great shell for those who are slow typists and/or have trouble remembering Unix commands.
The 1 denotes standard output (stdout). The 2 denotes standard error (stderr). So 2>&1 says to send standard error to where ever standard output is being redirected as well.
In tcsh redirection the ! symbol means overwrite the existing file even if noclobber
is set.
In other words, if noclobber is set then:
cmd > file
will write stdout
to file if file does not existcmd > file
will fail if file existscmd >> file
will append stdout
to file if file existscmd >> file
will fail if file does not existcmd >! file
will write stdout
to file, overwriting any existing filecmd >>! file
will append stdout
to file, creating the file if it does not already existIf noclobber
is not set then the ! has no effect:
cmd > file
will write stdout
to file, overwriting any existing filecmd >> file
will append stdout
to file
cmd >! file
will write stdout
to file, overwriting any existing filecmd >>! file
will append stdout
to file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With