你很可能正在使用bash,也可能是csh。你可能听说过sh、tcsh。如果你安装过EDA,就知道某EDA要正常工作必须要装ksh。另外你可能还听某大神安利过zsh……
那这么多shell有什么联系和区别,我们先来看看它们的历史和关系。下图基于维基百科资料整理:
那么这么多shell,我们ICer该如何选择呢?看以下几条信息:
基于以上的分析,对于普通ICer,我们的结论是:
另外,由于Tcl、Perl、Python等脚本语言的强大,我们只需要了解和掌握shell的常见、简单用法即可。把复杂的编程交给Tcl/Perl/Python去做吧。
注释
# this is comment
用户配置文件
#bash
~/.bashrc
#tcsh
~/.tcshrc 或 ~/.cshrc
#zsh
~/.zshrc
脚本第一行指定解释器
#!/bin/bash
#!/bin/tcsh
#!/bin/zsh
变量定义,赋值,引用
#bash
CompanyInfo="AI Chips, Co. LTD"
EDA_HOME=/tools/eda
echo $EDA_HOME
my_array=(1 2 3 4)
echo ${my_array[0]} #output is 1
my_hash['first']=1
my_hash[second]=2
echo ${my_hash[first]}
#tcsh
CompanyInfo = "AI Chips, Co. LTD"
set EDA_HOME = /tools/eda
echo $EDA_HOME
set my_array = (1 2 3 4)
echo $my_array[1] #output is 1
#zsh
CompanyInfo="AI Chips, Co. LTD"
EDA_HOME=/tools/eda
echo $EDA_HOME
my_array=(1 2 3 4)
echo $my_array[1] #output is 1
decare -A my_hash
my_hash['first']=1
my_hash[second]=2
echo $my_hash[first]
Tips:
环境变量
#bash, zsh
export NOVAS_HOME=/tools/eda/synopsys/novas
或者
NOVAS_HOME=/tools/eda/synopsys/novas
export NOVAS_HOME
#tcsh
setenv NOVAS_HOME /tools/eda/synopsys/novas
Tips:
数值计算
#bash, zsh
count=100
let count++
echo $count
#101
#csh
@ count = 100
@ count++
echo $count
#101
Tips:
((count++))
来做数值计算。条件
#bash, zsh
foo="a"
if [ $foo = "a" ]; then
echo "equal"
fi
#csh
set foo = "a"
if($foo == "a")then
echo "equal"
endif
Tips:
循环
#bash
arr=("a" "b" "c")
for((i=0; i<${#arr[*]}; i++))
do
echo ${arr[$i]}
done
#tcsh
set arr = (a b c)
foreach i ($arr)
echo $i
end
#zsh
arr=("a" "b" "c")
echo $arr
for ((i=1; i <= $#arr; i++)) {
echo $arr[$i]
}
for i ($arr) {
echo $i
}
Tips:
函数
#bash, zsh
function sum(){
return $(($1+$2))
}
sum 1 2
echo "sum = $?"
Tips:
下面是tcsh里用alias实现类似求和函数sum的例子。alias只是起到简化代码的作用,相当于宏定义。
#tcsh
alias sum '@ sum = $a + $b'; echo $sum
set a = 1
set b = 2
sum #output is 3
set b = 10
sum #output is 11
bash
菜鸟教程
http://www.runoob.com/linux/linux-shell.html
IBM Bash实例教程
https://www.ibm.com/developerworks/cn/linux/shell/bash/bash-1/index.html
https://www.ibm.com/developerworks/cn/linux/shell/bash/bash-2/index.html
https://www.ibm.com/developerworks/cn/linux/shell/bash/bash-3/index.html
PCWDLD
https://www.pcwdld.com/bash-cheat-sheet
GNU Bash参考手册
http://www.gnu.org/software/bash/manual/bash.html
tcsh
IBM Tcsh shell变量
https://www.ibm.com/developerworks/cn/aix/library/au-tcsh/index.html
tcsh - unix, linux command
http://www.tutorialspoint.com/unix_commands/tcsh.htm
杜克大学的一篇c shell教程
https://www2.cs.duke.edu/csl/docs/csh.html
grymoire
https://www.grymoire.com/Unix/Csh.html
Top Ten reasons not to use the C shell
https://www.grymoire.com/Unix/CshTop10.txt
zsh
陌辞寒的zsh开发指南
https://github.com/goreliu/zshguide
池建强的zsh的介绍、安装和配置
http://macshuo.com/?p=676
一个合格ICer,必需要熟练掌握常用的Linux命令。今天来介绍一下IC设计中常用的Linux命令。
http://exasic.com/article/index.php?md=linux-01