【发布时间】:2016-04-18 22:21:31
【问题描述】:
我有一个包含所有 tgz 文件的目录。目前,我有一个可以运行的脚本
- 将目录作为第一个参数
- 提取
tgz -
cd进入解压文件夹 - 然后运行我的加载脚本
- 然后继续下一个 tgz..
如下所示。
目前这个脚本可以工作,但是如果有人输入一个参数而不是目录名(例如,./myScript /whole/path/to/directory),它将失败
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循环。