csh(tcsh)

来源:互联网 发布:java 调用浏览器 编辑:程序博客网 时间:2024/04/30 05:59

1. TC Shell Initialize
/etc/csh.cshrc /etc/csh.login
.cshrc

2. Prompt

# The primary prompt set prompt = "$LOGNAME > "# The secondary prompt?3. Variable# local variableset name = "Tom"# global variablesetenv ORACLE_SID ora11g# read a line of inputset name = $<4. argumentsecho $1 $2 $3echo $*echo $argv[1] $argv[2] $argv[3]echo $argv[*]echo $#argv    # the number of arguments5. arithmetic@ num = 4 + 6@ num++

6. Manipulating Stack Directory
pushd: Push DIR to directory-stack, and cd to DIR
popd: Pop DIR from directory-stack, and cd to DIR
dirs -v: Display the numbered directory stack.

7. Redirect

command > file      # stdoutcommand >& file # stdout & stderrcommand | command       # stdoutcommand |& command      # stdout & stderrcommand >! file # override noclobber effectsls -l > ls.txtset noclobberls -l > ls.txt      # ls.txt: File exists.ls -l >! ls.txt

8. Test variable whether is set

echo $?variable    # 0(false, not set), 1(true)

9. Arrays

set fruit = ( apples pears peaches plums )echo $fruit            # apples pears peaches plumsecho ${fruit[1]}       # applesecho $fruit[2-4]       # pears peaches plumsecho $fruit[*]         # apples pears peaches plumsecho $#fruit           # 4echo $fruit[$#fruit]   # plumsset fruit[2] = bananasecho $fruit            # apples bananas peaches plumsshift fruitecho $fruit            # bananas peaches plums

10. Special Variables

$?var  Return 1 if variable has been set, 0 if not$#var  Print the number of elements in an array$$        Print the PID of current shell$<     Accept a line of input user up to newline. set name = $<

11. Modifier
Modifier
Meaning
Example
Result
:r
Root
echo pn:r/home/ellie/prog/check:hHeadechopn:h
/home/ellie/prog
:t
Tail
echo pn:tcheck.c:eExtensionechopn:e
c
:g
Global
echo $p:gt

set pv = /home/ellie/prog/check.c
echo pv:r # /home/ellie/prog/check  
echo
pv:h # /home/ellie/prog
echo pv:t # check.c  
echo
pv:e # c

set pv = (/home/*)
echo $pv:gt

**12. Quoting**

Single-Quate: except history(bang) character(!)
Double-Quate: expect history(bang) character(!) and the dollar sign($)

:q is used to replace the double quates
set name = “Daniel Savage”
grep name:qa.txtgrepname” a.txt

:x prevents the shell from expanding wildcards
set things = “*.pl a.??? my[1-5]”
echo things       # check.pl a.txt  
echo “
things” # *.pl a.??? my[1-5]
set newthings = ( things)echo#newthings # 2
set newthings1 = ( things:x)echo#newthings1 # 3

history -T

**13. Completion**

To complete the command name, filename, variable name automatically.

set autolist

To ignore certain filename extensions while filename completion is in use.

set fignore = ( .o .gif )

Tab completion will ignore case

set complete = enhance
ls -l /bin/GAWK => /bin/gawk

Types of completion

p: postion-dependent p/1/: postion 1, the first argument

complete cd ‘p/1/d/’

set hosts = (10.137.5.95 10.186.22.150)
complete telnet ‘p/1/$hosts/’
telnet
10.137.5.95 10.186.22.150

**14. sched, a built-in command, to create a list of jobs that will be scheduled to run at some specific time.**

sched 16:00 echo ‘Time to start your lecture!’

**15. Case modifiers**:u  Uppercase the first letter of a word:l  Lowercase the first letter of a word:a  Apply a modifier to an entire word

set name = ‘nicky’
echo name:uNickyechoname:au
NICKY
set names = (‘nicky’ ‘mike’)
echo names:uNickymikeechonames:gu
Nicky Mike
echo $names:gau
NICKY MIKE

**16. TC SHELL built-ins**builtins**17. Prevent the .cshrc or .tcshrc file from being read into your script, -f(fast)**\#!/bin/csh -f**18. setuid script**\#!/bin/csh -feb-f  fast start up, don't execute .cshrc-e  abort immediately if interrupted-b  this is a setuid script

chmod 4755 myscrit

**19. control statement**

if ( -e file ) then

endif

while ( a<=2)echoa
@ a = $a - 1
end

foreach color (red blue green)
echo $color
end
“`

0 0
原创粉丝点击