linux 指令碼 source sh. ./不同的方式下開啟指令碼$0的不同
阿新 • • 發佈:2021-02-19
新建一個測試指令碼test_if.sh
#!/bin/bash
if [ $# -lt 1 ]; then
echo "usage: $0 tf|onnxruntime|pytorch|tflite [resnet50|mobilenet|ssd-mobilenet|ssd-resnet34] [cpu|gpu]"
fi
使用不同方式開啟
1這裡發現./是需要許可權才能開啟的
2這裡
0
其
實
是
進
程
的
名
字
s
h
和
.
/
創
建
子
進
程
,
米
i
n
g
z
i
分
別
為
t
e
s
t
i
f
.
s
h
和
.
/
t
e
s
t
i
f
.
s
h
,
而
s
o
u
r
c
e
在
本
體
這
名
字
為
b
a
s
h
3
0其實是程序的名字sh和./建立子程序,米ingzi分別為test_if.sh和./test_if.sh,而source在本體這名字為bash 3
0其實是進程的名字sh和./創建子進程,米ingzi分別為testif.sh和./testif.sh,而source在本體這名字為bash3 #:傳入指令碼的引數個數;
$0: 指令碼程序的名稱;
$1: 傳入指令碼的第一個引數;
$2: 傳入指令碼的第二個引數;
[email protected]: 傳入指令碼的所有引數;
$*:傳入指令碼的所有引數;
$$: 指令碼執行的程序id;
$?: 上一條命令執行後的狀態,結果為0表示執行正常,結果為1表示執行異常;