Linux下編寫shell文件的一些規(guī)范和語(yǔ)法:Linux中編寫Shell腳本
$'\r':command not found
Windows下編寫文件僻弹,拷貝到Linux系統(tǒng)下執(zhí)行會(huì)出現(xiàn)此問(wèn)題。Windows文檔每行結(jié)尾是"\r\n"违孝,Unix的結(jié)尾是"\n"腺怯,因此會(huì)報(bào)錯(cuò)。
參考shell腳本執(zhí)行錯(cuò)誤 $'\r':command not found
字符串操作
- 字符串拼接
export var=/tmp
echo "$var/log.txt"
## touch拼接
var1=log.txt
touch $var"/"$var1
## 輸出 /tmp/log.txt
## 截取文件名和文件目錄
# 參考 https://blog.csdn.net/u010670689/article/details/53425111
export var=./result/frame_0089_pred.hdr
echo ${var##*/}
# 輸出 frame_0089_pred.hdr