我有这个脚本外壳,我想在Windows中执行它:
#!/bin/sh
# Create the structure of folders that will contain the result files
export perl_git_dir=path1
export OUTPUT_DIR=path2
mkdir $OUTPUT_DIR/output_perl
for FILE in `ls *.sh`
do
echo "file is:"$FILE
if [ -f "$FILE" ];then
name=${FILE%.*}
mkdir -p $OUTPUT_DIR/output_perl/"$name"
fi;
done
for entry in `ls *.sh`
do
if [ -f "$entry" ];then
echo "enty is "$entry
echo "$entry" >> stdout.txt
echo "$entry" >> stderr.txt
./$entry >> stdout.txt 2>> stderr.txt
fi;
done
我得到的结果是: 创建目录,然后在“ stderr.txt”文件中出现此重复错误
mkdir: cannot create directory ‘path1/output_perl’: File exists
答案 0 :(得分:1)
代码似乎可以完成应有的工作。在我的示例中,我用.sh
替换了.pl
,因为我周围没有任何脚本文件。注意:预计会出现执行错误。
我只能认为问题太不完整,无法回答...
#!/bin/sh
_output_dir=path2
for f in *.pl; do
basename=${f%.*}
mkdir -p ${_output_dir}/output_perl/${basename}
echo ${f} >>stdout.txt
echo ${f} >>stderr.txt
./${f} >>stdout.txt 2>>stderr.txt
done
exit 0
试运行:
$ sh dummy.sh
$ cat stdout.txt
dummy2.pl
dummy.pl
standard.pl
$ cat stderr.txt
dummy2.pl
dummy.sh: line 9: ./dummy2.pl: Permission denied
dummy.pl
dummy.sh: line 9: ./dummy.pl: Permission denied
standard.pl
dummy.sh: line 9: ./standard.pl: Permission denied
$ ls path2/output_perl/
dummy dummy2 standard