Shell script之if...then
1 Variable in shell
If you want to print variable, then use echo command.
In front of the variable to add $variabel or use ${variable} to fetch the value of variable.
# echo $variable
# echo $PATH
2 if....then
if condition
then
condition is true
execute all commands up to else statement
else
if condition is not true then
execute all commands up to fi
fi
3 Example
1 #!/bin/bash
2 # ----------------------------------------------------------------------------
3 # call pythonscript, then modelsim
4 # ----------------------------------------------------------------------------- if [ $# -eq ]; then
here=$PWD;
cd '../../02_modelsim' # work directory in your project
vsim -gui&
cd $here;
elif [ $ == "-h" ]; then
12 # questasim-doc:
evince /Software/AMS/current/questasim/v10.3b/docs/pdfdocs/_bk_questa_sim.pdf &
fi
4 Explanation
`$` refer to `value of` and
`#` refer to `number of / total number`
So together
`$#` refer to `The value of the total number of command line arguments passed.`
Thus, you can use $# to check the number of arguments/parameters passed like you did and handle any unexpected situations.
`$1` for `value of 1st argument passed`
`$2` for 'value of 2nd argument passed`
Shell script之if...then的更多相关文章
- shell及脚本4——shell script
一.格式 1.1 开头 必须以 "# !/bin/bash" 开头,告诉系统这是一个bash shell脚本.注意#与!中间有空格. 二.语法 2.1 数值运算 可以用decla ...
- shell script
一.shell script的编写与执行 1.shell script 的编写中还需要用到下面的注意事项: a.命令的执行是从上到下,从左到右地分析与执行 b.命令.参数间的多个空白都会被忽略掉 c. ...
- (copy) Shell Script to Check Linux System Health
source: http://linoxide.com/linux-shell-script/shell-script-check-linux-system-health/ This article ...
- shell script练习
执行脚本的几种方式: 1. sh a.sh 或者 bash a.sh 调用的是 /bin/bash 进程执行的,所以脚本不需要执行权限. 2. 直接使用绝对路径执行, /home/script/a ...
- 这些年我们一起搞过的持续集成~Jenkins+Perl and Shell script
这些年我们一起搞过的持续集成~Jenkins+Perl and Shell script ##转载注明出处:http://www.cnblogs.com/wade-xu/p/4378224.html ...
- CentOS Linux下一个tomcat起停,查看日志的shell script
CentOS 的tomcat安装目录:/usr/local/tomcat vi MyTomcatUitl.sh 创建文件chmod u+x MyTomcatUtil.sh 赋执行 ...
- Shell script for logging cpu and memory usage of a Linux process
Shell script for logging cpu and memory usage of a Linux process http://www.unix.com/shell-programmi ...
- shell script入门
从程序员的角度来看, Shell本身是一种用C语言编写的程序,从用户的角度来看,Shell是用户与Linux操作系统沟通的桥梁.用户既可以输入命令执行,又可以利用 Shell脚本编程,完成更加复杂的操 ...
- shell script 的追踪与 debug
shell script 的追踪与 debug scripts 在运行之前,最怕的就是出现语法错误的问题了!那么我们如何 debug 呢?有没有办法不需要透过直接运行该 scripts 就可以来判断是 ...
- 第十三章、学习 Shell Scripts 简单的 shell script 练习
简单的 shell script 练习 简单范例 对谈式脚本:变量内容由使用者决定 [root@www scripts]# vi sh02.sh #!/bin/bash # Program: # Us ...
随机推荐
- 使用ExtJs实现文件下载
文件下载,是不可以直接通过Ext.Ajax.Request来实现的.一般的,可以通过创建一个隐藏的form表单来实现.具体代码以及代码注释如下: if (!Ext.fly('downForm')){ ...
- psycopg2.pool – Connections pooling / psycopg2.pool – 连接池 / postgresql 连接池
创建新的PostgreSQL连接可以是一个昂贵的操作.这个模块提供了一些纯Python类直接在客户端应用程序实现简单的连接池. class psycopg2.pool.AbstractCon ...
- UVA 11019 Matrix Matcher(ac自动机)
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- C#的运算符重载
运算符重载看起来与标准静态方法声明类似,但它们使用关键字operator和运算符本身,而不是一个方法名: public static 返回类型 operator +(类型1 变量1,类型2 变量2) ...
- Head first javascript
基础 <script type="text/javascript"> function validateNumber(value) { // Validate the ...
- aop郁闷错误
很郁闷的错误,终于解决了: <aop:config> <aop:aspect ref="log"> <aop:pointcut id=" ...
- java连接mysql的一个小例子
想要用java 连接数据库,需要在classpath中加上jdbc的jar包路径 在eclipse中,Project的properties里面的java build path里面添加引用 连接成功的一 ...
- 日期选择插件clndr的使用
需求是:在HTML中绘制日历直接供用户选择 而不是使用datepicker之类的表单插件让用户点击input后弹出datepicker让用户选择 浏览了一些解决方案后,发现 CLNDR 这个jQue ...
- 51nod1354 选数字
01背包tle. 解题报告(by System Message) 类似于背包的DP,以乘积为状态.先把等选数字里面不是K约数的去掉.然后找出K的约数,进行离散化.然后dp[i][j]表示前i个数字乘积 ...
- 51nod1122 机器人走方格 V4
矩阵快速幂求出每个点走n步后到某个点的方案数.然后暴力枚举即可 #include<cstdio> #include<cstring> #include<cctype> ...