您的位置:首页 > 其它

csh(tcsh)

2016-03-21 23:45 387 查看
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 variable
set name = "Tom"

# global variable
setenv ORACLE_SID ora11g

# read a line of input
set name = $<

4. arguments
echo $1 $2 $3
echo $*
echo $argv[1] $argv[2] $argv[3]
echo $argv[*]
echo $#argv    # the number of arguments

5. 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      # stdout
command >& file # stdout & stderr

command | command       # stdout
command |& command      # stdout & stderr

command >! file # override noclobber effects

ls -l > ls.txt
set noclobber
ls -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 plums
echo ${fruit[1]}       # apples
echo $fruit[2-4]       # pears peaches plums
echo $fruit[*]         # apples pears peaches plums
echo $#fruit           # 4
echo $fruit[$#fruit]   # plums
set fruit[2] = bananas
echo $fruit            # apples bananas peaches plums
shift fruit
echo $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:r
/home/ellie/prog/check
:h
Head
echo pn:h

/home/ellie/prog

:t

Tail

echo pn:tcheck.c:eExtensionechopn:t
check.c
:e
Extension
echo pn:e

c

:g

Global

echo $p:gt

set pv = /home/ellie/prog/check.c

echo pv:r # /home/ellie/prog/check
echopv:r # /home/ellie/prog/check
echo pv:h # /home/ellie/prog

echo pv:t # check.c
echopv: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.txtgrep“name:q a.txt
grep “name” a.txt

:x prevents the shell from expanding wildcards

set things = “*.pl a.??? my[1-5]”

echo things # check.pl a.txt
echo “things # check.pl a.txt
echo “things” # *.pl a.??? my[1-5]

set newthings = ( things)echothings )
echo #newthings # 2

set newthings1 = ( things:x)echothings: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:u
Nicky
echo name:au

NICKY

set names = (‘nicky’ ‘mike’)

echo names:uNickymikeechonames:u
Nicky mike
echo names: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 <= 2 )
echo a

@ a = $a - 1

end

foreach color (red blue green)

echo $color

end

“`
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: