读取程序名.sh Shell 脚本

Shell 片段 · codes/shell/输入和输出/读取程序名.sh · 11 行

源码

#!/usr/bin/env bash

# testing the $0 parameter

echo The command entered is $0

#当传给$0变量的真实字符串是整个脚本的路径是,程序中就会使用整个路径,而不仅仅是程序名

name=`basename $0`
echo The command entered is $name

查看上游源码 ↗

内容与示例整理自 dunwu/linux-tutorial,遵循 CC BY-SA 4.0;本站保留原作者署名与许可,命令仅供学习,执行前请核对目标环境。