本文共 5934 字,大约阅读时间需要 19 分钟。
全局变量的定义setenv v value 该变量将被此shell派生的所有子shell继承。
将命令的输出和错误输出分别重定向(cmd > goodstuff) >& badstuff。
command<<WORD 表示将command的输入重定向为从第一个WORD处开始,到下一个WORD处之间的内容(即here文档)。
continue
break
16 csh中设置环境变量PATH的方法
csh中使用path代替PATH,设置类似于数组的使用。
set path = ($path /home)
echo $path
echo $PATH
17 source等价于其他shell中的.
source使得程序在当前的shell中被执行,而不是派生子进程来执行。
18转义字符与单双引号
双引号保护除历史字符(!),变量替换字符($)和反引号(用于命令替换)之外的所有元字符,使其不被解释。
19 历史command
!!用来执行上一条命令。
20 pushd和popd用来维护目录栈
21 csh -vx用来显示输入的原样和变量替换后的脚本,用来帮助调试。
22在脚本中处理中断
23 noclobber 禁止覆盖变量,设定 $noclobber 预设变量改变输出重定向特性.
#!/bin/csh -vx#csh -vx show the command before running to help debug#just to check syntax#csh -n $0#argvif ($#argv < 2) then echo "Sorry, but you entered too few parameters" echo "usage: $0 arg1 arg2 exitendifset arg1 = $1set arg2 = #2foreach i ($*) echo $iend #execute commandsecho "Hello there `whoami`. How are you today?"echo "You are currently using `hostname` and the time is `date`"echo "Your directory is `pwd`"whoamihostnamedatepwd#varset name = Markecho $nameset name = "Mark Meyer" # if the string has space, must use ""echo $name# it means set to NULLset name = unset name# get user inputset x = $< set current_user = `whoami`#buildin varsecho $user # who am I?echo $status # a numeric variable, usually used to retun error codes#Arithmetic variables@ i = 2@ k = ($x - 2) * 4@ k = $k + 1@ i--@ i++#arrayset name = (mark sally kathy tony)echo $#name # num of the arrayecho $name[1]echo $name[4]echo $name[2-3]echo $name[2-] # all elements from 2 to the endecho $name[1-3]echo $name[$i]set name = ($name doran)set name = (doran $name)set name = ($name[1-2] alfie $name[3-])shift name # get rid of the frist element of the arrayshift #if no argument is given, it will get rid of argv#Expressions and operators== equal (either strings or numbers)!= not equal (either strings or numbers)=~ string match!~ string mismatch<= numerical less than or equal to>= numerical greater than or equal to> numerical greater than< numerical less than-e file file merely exists (may be protected from user)-r file file exists and is readable by user-w file file is writable by user-x file file is executable by user-o file file is owned by user-z file file has size 0-f file file is an ordinary file-d file file is a directory! -- negate && -- logical and|| -- logical or#if-else# run cmd as if expressionif ({grep -s junk $1}) then echo "We found junk in file $1"endif# check if the var is definedif ($?dirname) then ls $dirnameendifif (-e somefile) then grep $1 somefileelse echo "Grievous error! Database file does not exist".endif#foreachforeach i (*) if (-f $i) then echo "============= $i ===================" head $i endif if (-d $i) then (cd $i; headers) endifend#whilewhile ($#argv > 0) grep $something $argv[1]end@ n = 5while ($n) # do something @ n--end#switch-caseswitch ($argv[$i]) case quit: break # leave the switch statement case list: ls breaksw case delete: case erase: @ k = $i + 1 rm $argv[$k] breakswendsw #here documentgrep $i <tempdata <
转载地址:http://dalnb.baihongyu.com/