我有一個包含所有tgz
文件的目錄。目前,我有我運行會已更新:Bash腳本提取目錄中的所有.tgz
- 您可以在目錄中第一個參數的腳本
- 提取
tgz
cd
到提取的文件夾- ,然後運行我的負載腳本
- 並繼續下一個tgz ..
如下所示。
目前這個腳本的工作,但如果有人不僅僅是目錄名稱(例如,./myScript /全/路徑/到/目錄)
dirname=$1
cur_dir=`pwd`
echo The directory you are about to extract is $dirname
echo $(ls ${cur_dir}/${dirname}/*.tgz)
echo Your current directory is ${cur_dir}
for tgz in $(ls ${cur_dir}/${dirname}/*.tgz) ; do # <---- I think there is a better way of doing this please advise
echo the tgz you are about to extract now is ${tgz}
cd ${dirname}; #cd into input directory
tar -xvzf ${tgz}; #extract tgz
cd ${tgz%%.tgz}; #cd into the folder you extracted
loadItExit; #run my other script to load
cd ../..; #move up two levels back to original path
done
'for fname in $ {FNAME%/ *}/* TGZ。 do'將循環到第一個給定文件的目錄中的所有'* .tgz'。 – Kellerspeicher