Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do >! and >>! do in tcsh

Tags:

redirect

tcsh

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?

like image 556
Peter Smit Avatar asked Jul 20 '11 13:07

Peter Smit


People also ask

What does tcsh command do?

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.

What is the function of the &> Redirect symbol?

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.

What is tcsh and csh?

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.

What does the 2 >& 1 at the end of the following command mean?

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.


1 Answers

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 exist
  • cmd > file will fail if file exists
  • cmd >> file will append stdout to file if file exists
  • cmd >> file will fail if file does not exist
  • cmd >! file will write stdout to file, overwriting any existing file
  • cmd >>! file will append stdout to file, creating the file if it does not already exist

If noclobber is not set then the ! has no effect:

  • cmd > file will write stdout to file, overwriting any existing file
  • cmd >> file will append stdout to file
  • cmd >! file will write stdout to file, overwriting any existing file
  • cmd >>! file will append stdout to file
like image 163
Tom Avatar answered Sep 21 '22 14:09

Tom