写一个简单的脚本

 vim var

脚本内容如下:

#!/bin/sh
echo "the number of parameters passed to the script: $#"
echo "the name of the script itself: $0"
echo "the first parameter passed to the shell script: $1"
echo "the second parameter passed to the shell script: $2"
echo "the list of all the parameters passed to the script(some string): $@"
echo "the list of all the parameters passed to the script(one string): $*"
echo "the current process ID number of the script which is running: $$"
echo "the return value of the last shell command performed: $?"
保存退出。
 
赋予脚本执行权限:
 chmod +x var

执行脚本:

# ./var i j k
the number of parameters passed to the script: 3
the name of the script itself: ./var
the first parameter passed to the shell script: i
the second parameter passed to the shell script: j
the list of all the parameters passed to the script(some string): i j k
the list of all the parameters passed to the script(one string): i j k
the current process ID number of the script which is running: 3746
the return value of the last shell command performed: 0

通过显示结果可以看到:

$# 是传递给脚本的参数个数;
$0 是脚本本身的名字;
$1 是传递给该shell脚本的第一个参数;
$2 是传递给该shell脚本的第二个参数;
$@ 是传递给脚本的所有参数的列表(是多个字符串,每个参数为1个字符串);
$* 是传递给脚本的所有参数的列表(以一个单字符串显示所有参数),与位置变量不同,参数可超过9个;
$$ 是运行脚本的当前进程ID号;
$? 是显示执行上一条Shell命令的返回值,0表示没有错误,其他表示有错误。

随机推荐

  1. linux下c语言实现简单----线程池

    这两天刚好看完linux&c这本书的进程线程部分,学长建议可以用c语言实现一个简单的线程池,也是对线程知识的一个回顾与应用.线程的优点有好多,它是"轻量级的进程",所需资源 ...

  2. LoadRunner12浏览器录制(谷歌火狐)

    一.使用谷歌浏览器 下载的版本 65.0.3325.162(正式版本)(64 位)安装之前要记得把电脑现有的谷歌浏览器卸载了. 1.下载地址:https://www.chromedownloads.n ...

  3. JDK 之 Arrays.asList - 源码分析

    Arrays工具类提供了一个方法asList, 使用该方法可以将一个变长参数或者数组转换成List . 其源代码如下: @SafeVarargs public static <T> Lis ...

  4. 通过t-sql定期自动备份SQL Server 上的所有数据库

    项目背景 解决方案 方案一,是采用SQL的定时备份,建立作业来操作,这里有完整的使用手册: 方案二:基于t-sql方法进行查询备份 方案思路: 1.1 在 Master 数据库上创建一个备份所有数据库 ...

  5. Spring Cloud Gateway实战之四:内置predicate小结

    欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...

  6. 本机不安装Oracle客户端,使用instantclient_11_2和PLSQL Developer连接Oracle远程数据库步骤

     前言:由于Orcale客户端,占用空间太大,我们选择安装installclient\PLSQL客户端对orcale进行数据库连接. 安装要求.installClient要与PLSQL的安装位数一致, ...

  7. 菜鸡的Java笔记 第二十五 wrapperClass 包装类

    wrapperClass 包装类         1.包装类的特点        2.装箱与拆箱操作        3.数据转型处理            内容        Object 类可以接收 ...

  8. 14-2-Unsupervised Learning ----Word Embedding

    Introduction 词嵌入(word embedding)是降维算法(Dimension Reduction)的典型应用 那如何用vector来表示一个word呢? 1-of-N Encodin ...

  9. [atARC110E]Shorten ABC

    考虑令$a$.$b$和$c$分别对应1.2和3,那么每一次相当于令$x$和$y$变为$x\oplus y$(要求$x\ne y$) 根据异或的结合律,我们相当于将其划分为若干个区间求异或值 (另外还有 ...

  10. Object类的toString和Equals方法,以及Objects类的Equals方法

    Object类 toString()方法 public class Person { private String name; private int age; public Person() { } ...