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 ...
随机推荐
- Mac 版 QQ 可直接访问 iPhone 的相册 ?!
在QQ的聊天窗口中,点击 发送图片 的按钮,会有两个选择项,其中一个就是 从iPhone相册中选取 ,如图 点击 从iPhone相册中选取 后,iPhone上的QQ会收到一条消息 “请选择要上传的照 ...
- git提交代码步骤
01:首先git status一下查看当前目录下修改的文件,当然编译生成的文件也在其中,我们只看自己修改的: 02:git add ****** //(文件名) 将上述查找到自己修改的文件添加到git ...
- BZOJ 2115 Xor(抑或值最大路径)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2115 题意:给出一个带权无向图.求一条1到n的路径使得路径上权值的抑或值最大? 思路:( ...
- MongoDB 学习笔记(一)基础篇
1.MongoDB 特点 面向集合存储,存储对象类型的数据方便 模式自由,不需要定义任何模式(schma) 动态查询 完全索引,包含内部对象 复制和故障恢复方便 高效的二进制数据存储 支持c# 平台驱 ...
- 转:java中scanner类的用法
声明:本文转自百度经验:http://jingyan.baidu.com/article/e73e26c0c74a1f24adb6a7fb.html Scanner是SDK1.5新增的一个类,可是使用 ...
- 在单机Hadoop上面增加Slave
之前的文章已经介绍了搭建单机Hadoop, HBase, Hive, Spark的方式:link 现在希望在单机的基础上,加一个slave. 首先需要加上信任关系,加信任关系的方式,见前一篇文章:li ...
- hibernate annotation配置经验
1.将annotation写在entity类文件的get方法上面
- Qt之国际化(系统文本-QMessageBox按钮、QLineEdit右键菜单等)
简介 使用Qt的时候,经常会遇到英文问题,例如:QMessageBox中的按钮.QLineEdit.QSpinBox.QScrollBar中的右键菜单等.通常情况下,我们软件都不会是纯英文的,那么如何 ...
- VC++菜单
2.1 如何动态添加和删除菜单项 AppendMenu InsertMenu DeleteMenu ////////////////////////////////////////////////// ...
- 安装CouchbaseClient的过程中提示 Error 1935.An error occurred during the installation of assembly;Error:-1603 fatal error during installation
安装过程中提示报错 点击确定后 安装程序会接着回滚,又提示报错如下 Error 1935的解决方法是下载一个微软的补丁. http://support.microsoft.com/de ...