cur*_*ous 3 scripting bash shell-script
我有扩展名为.AH
. 例如:
aa.AH
bb.AH
cc.AH
dx.AH
tmz.AH
lght.AH
Run Code Online (Sandbox Code Playgroud)
我想选择所有这些文件,但不是一个一个选择,因为我使用saclst
(这是一个读取和写入地震图标题的命令),并且它需要所有文件进行 NPTS 比较(即点数)。所以我使用这个代码:
for file in *AH
do
nptsAH=$(saclst npts f ${file}* > nptsAH.txt | awk '{print $2}' nptsAH.txt | sort -n | head -1)
declare -i nptsAH
sac << !
r $file
interpolate NPTS $nptsAH
w over
q
!
done
Run Code Online (Sandbox Code Playgroud)
哪种形式适合 bash 脚本?
一个变量不能保存多个文件或一个模式。但是你可以使用一个数组:
files=(*.AH)
Run Code Online (Sandbox Code Playgroud)
或者
files=()
for file in *.AH; do
files+=("$file")
...
some_command using "$file"
done
...
some_command using "${files[@]}"
Run Code Online (Sandbox Code Playgroud)
另见。