我正在尝试使用 svn2git 将一些模块从 SVN 迁移到 GIT。我在 .csv 文件中有一个模块列表,如下所示:
pl.com.neokartgis.i18n;pl.com.neokartgis.i18n;test-gis;svniop
pl.com.neokartgis.cfg;pl.com.neokartgis.cfg;test-gis;svniop
pl.com.neokart.db;pl.com.neokart.db;test-gis;svniop
我想将每个模块迁移到单独的 GIT 存储库。我尝试了以下脚本,该脚本从 .csv 文件中读取模块列表并循环导入每个模块:
#!/bin/bash
LIST=$1
SVN_PATH=svn://svn.server/path/to/root
DIR=`pwd`
function importToGitModule {
cd $DIR
rm -rf /bigtmp/svn2git/repo
mkdir /bigtmp/svn2git/repo
cd /bigtmp/svn2git/repo
svn2git --verbose $SVN_PATH/$1
#some other stuff with imported repository
}
cat $LIST | gawk -F";" '{ print $2; }' | while read module_to_import
do
echo "before import $module_to_import"
importToGitModule "$module_to_import";
done;
问题是脚本在第一次迭代后结束。但是,如果我删除对 svn2git
的调用,脚本将按预期工作并为文件中的每个模块打印消息。
我的问题是:为什么这个脚本在第一次迭代后结束,我如何更改它以循环导入所有模块?
编辑:
以下循环版本可以正常工作:
for module_to_import in `cat $LIST | gawk -F";" '{ print $2; }'`
do
echo "before import $module_to_import"
importToGitModule "$module_to_import";
done;
那么为什么 while read
不起作用?
最佳答案
我怀疑你的循环中的某些东西——可能是 svn2git
进程的一部分——正在消耗 stdin
。考虑这样一个循环:
ls /etc | while read file; do
echo "filename: $file"
cat > /tmp/data
done
无论/etc
中有多少文件,这个循环只会运行一次。此循环中的 cat
将消耗 stdin
上的所有其他输入。
你可以通过从/dev/null
显式重定向stdin
来查看你是否遇到过同样的情况,就像这样:
cat $LIST | gawk -F";" '{ print $2; }' | while read module_to_import
do
echo "before import $module_to_import"
importToGitModule "$module_to_import" < /dev/null
done
关于linux - 为什么 svn2git 导致循环在 bash 脚本中中断?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31312030/