写一个简单的脚本

 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. Java8新特性Stream流应用示例

    Java8新特性介绍 过滤集合 List<String> newList = list.stream().filter(item -> item != null).collect(C ...

  2. Celery Received unregistered task of type

    celery -A proj worker --loglevel=info 这个错误原因在于proj这里没有包含对应的task, 可以在这里导入需要的task即可

  3. IO流(二)

    一:字符流 字符输入流 写入文件字符流 import java.io.FileWriter; import java.io.IOException; //fileWriter public class ...

  4. Java学习(十六)

    今天先学了文本标签 <p> <strong>永远不要相信诺克萨斯人的血条!</strong><!--表示一段内容的重要性--> <br /> ...

  5. 18.Java 封装详解/多态详解/类对象转型详解

    封装概述 简述 封装是面向对象的三大特征之一. 封装优点 提高代码的安全性. 提高代码的复用性. "高内聚":封装细节,便于修改内部代码,提高可维护性. "低耦合&quo ...

  6. Nginx server_name翻译

    http://nginx.org/en/docs/http/server_names.html#regex_names 匹配优先顺序 精确名称,无通配符,无正则. 以星号开头的最长的通配符名称,例如& ...

  7. 如何设计一个高内聚低耦合的模块——MegEngine 中自定义 Op 系统的实践经验

    作者:褚超群 | 旷视科技 MegEngine 架构师 背景介绍 在算法研究的过程中,算法同学们可能经常会尝试定义各种新的神经网络层(neural network layer),比如 Layer No ...

  8. Docker部署 Mysql .Net6等容器

    Centos8安装Docker 1.更新一下yum [root@VM-24-9-centos ~]# yum -y update 2.安装containerd.io # centos8默认使用podm ...

  9. PAT A1039、A1047——vector常见用法

    vector 常用函数实例 (1)push_back() (2)pop_back() (3)size() (4)clear():清空vector中所有元素 (5)insert():insert(it, ...

  10. puts()_C语言

    puts()函数用来向标准输出设备, scanf函数是格式输入函数,即按用户指定的格式从键盘上把数据输入到指定的变量之中. puts就是输出字符串啊.int puts(    const char* ...