csh(tcsh)
2016-03-21 23:45
387 查看
1. TC Shell Initialize
/etc/csh.cshrc /etc/csh.login
.cshrc
2. Prompt
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
8. Test variable whether is set
9. Arrays
10. Special Variables
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
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
ls -l /bin/GAWK => /bin/gawk
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
sched 16:00 echo ‘Time to start your lecture!’
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
chmod 4755 myscrit
if ( -e file ) then
endif
while ( a<=2)echoa <= 2 )
echo a
@ a = $a - 1
end
foreach color (red blue green)
echo $color
end
“`
/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 autolistTo ignore certain filename extensions while filename completion is in use.
set fignore = ( .o .gif )Tab completion will ignore case
set complete = enhancels -l /bin/GAWK => /bin/gawk
Types of completion
p: postion-dependent p/1/: postion 1, the first argumentcomplete 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
“`
相关文章推荐
- PSP记录个人项目耗时情况
- 设计模式学习笔记——状态模式
- 工具类:拉伸一张图片(UIImage分类)
- 项目之RFID天线设计
- requests的content与text导致lxml的解析问题
- Spring源码之ApplicationContext(七)获取消息资源
- JAVA 基础 final关键字
- AndroidAutoLayout 屏幕适配
- Codeforces 400B Inna and New Matrix of Candies 【模拟】
- 图示aidl原理
- Android中SQLite数据库小计
- Android——关于Activity跳转的返回(无返回值和有返回值)——无返回值
- Spring源码之ApplicationContext(六)注册BeanPostProcessor
- 使用scm-manager搭建git/svn 代码管理仓库
- Objective-C探究alloc方法的实现
- Mysql绿色版安装配置
- C语言教程:第一节
- cocos2dx三种定时器的使用
- mybatis 数组报错 There is no getter for property named '__frch_item_0'
- Problem F: 删出多余的空格