1、安装插件(Bash Debug)
2、写launch.json
json
{
"version": "0.2.0",
"configurations": [
{
"type": "bashdb",
"request": "launch",
"name": "Debug Shell Script",
"program": "${file}",
"args": ["-t", "rk3588", "-a", "aarch64", "-d", "yolov8"],
"cwd": "${workspaceFolder}",
"pathBash": "/bin/bash",
// "pathBashdb": "/usr/bin/bashdb",
"terminalKind": "integrated"
}
]
}
3、shell的常用语法
echo
shell
echo 'hello shell' 单引号原样输出,不解析
echo "hello shell" 双引号解析变量
echo "hello ${name}"
echo "hello:$1" 输出第一个参数
echo "$name"
echo "${name}"
echo "当前目录:$(pwd)" ()是命令 {}是变量
if
json
if [ 命令 ]; then # []左右都要有空格
命令1
fi
# [[]] 更高级更安全
1、不需要给变量添加""也不容易报错
2、支持 && || 直接写到里面
3、支持> < 比较字符串
if [[$a -gt 10 && $a -It 30 ]];then
echo "ok"
fi
[-f file] # 是否普通文件
[-d dir] # 是否目录
[-e file] # 是否存在
[-z ${name}] # 字符串长度为0
exit -1