csh(tcsh)

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:hHeadecho pn:h
/home/ellie/prog
:t
Tail
echo pn:tcheck.c:eExtensionecho pn: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.txtgrep 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” # *.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:uNickyecho name:au
NICKY
set names = (‘nicky’ ‘mike’)
echo names:uNickymikeecho 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)echo a
@ a = $a - 1
end

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值