csh - yszheda/wiki GitHub Wiki

loop

#!/bin/csh
set z="/a/b/c/"
foreach i (`ls -d $z`)
 echo $i
end

string

extract chars

upper case / lower case

set ac `echo $AC | tr "[:upper:]" "[:lower:]"`

file

absolute path

readlink -f relative_file_name
ABS_PATH=`cd "$1"; pwd`

IO redirect

# redirect both standard output and error to a file with:
xxx >& filename

if

if ( { grep -q 'Pattern' file } ) then
  echo "Pattern found"
else
  echo "Pattern not found"
endif
grep -q 'Pattern' file
if ( $status == 0 ) then
  echo "Pattern found"
else
  echo "Pattern not found"
endif

PATH

set path = ($path /usr/local/bin)

history

set history = 2000          # History remembered is 2000
set savehist = (2000 merge) # Save and merge with existing saved 
set histfile = ~/.tcsh_history
 ...in .tcshrc and this line... 
history -S
 ...in .logout solved the problem.