Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Testing 使用给定目录中的输入运行特定程序的脚本_Testing_Maven_For Loop_Sh - Fatal编程技术网

Testing 使用给定目录中的输入运行特定程序的脚本

Testing 使用给定目录中的输入运行特定程序的脚本,testing,maven,for-loop,sh,Testing,Maven,For Loop,Sh,因此,我需要运行一系列(maven)测试,测试文件作为maven任务的参数提供 大概是这样的: mvn清洁测试-Dtest= 测试文件通常被组织到不同的目录中。因此,我正在尝试编写一个脚本,该脚本将执行上述“命令”,并自动将给定目录中所有文件的名称提供给-Dtest 所以我从一个名为“run_test”的shell脚本开始: #!/bin/sh if test $# -lt 2; then echo "$0: insufficient arguments on the command l

因此,我需要运行一系列(maven)测试,测试文件作为maven任务的参数提供

大概是这样的:

mvn清洁测试-Dtest=

测试文件通常被组织到不同的目录中。因此,我正在尝试编写一个脚本,该脚本将执行上述“命令”,并自动将给定目录中所有文件的名称提供给
-Dtest

所以我从一个名为“run_test”的shell脚本开始:

#!/bin/sh
if test $# -lt 2; then
    echo "$0: insufficient arguments on the command line." >&1
    echo "usage: $0 run_test dirctory" >&1
    exit 1
fi
for file in allFiles <<<<<<< what should I put here? Can I somehow iterate thru the list of all files' name in the given directory put the file name here?
     do mvn clean test -Dtest= $file  

exit $?
#/垃圾箱/垃圾箱
如果测试$#-lt 2;然后
echo“$0:命令行上的参数不足。”>&1
echo“用法:$0运行测试目录”>&1
出口1
fi

对于allFiles中的文件,假设
$1
包含目录名(验证用户输入是一个单独的问题),则

将在所有文件上运行comand。如果要递归到子目录,则需要使用
find
命令

for file in $(find $1 -type f)
do
    etc...
done

如果参数只给出目录名,而没有给出位置,该怎么办。换句话说,我确信给定的dir在
/”中的某个地方,但它可能在任何地方。那么,我是否应该对$(find$1-typed)中的文件使用
,`(d表示目录?)以及
[[-f$file]]
的含义是什么?将上述内容中的一个包装在
中,用于$(find.-typed-name$1)中的目录;做内环。。。完成
这是一个只选择文件并跳过任何子目录和链接的测试。
for file in $1/*
do
    [[ -f $file ]] && mvn clean test -Dtest=$file
done
for file in $(find $1 -type f)
do
    etc...
done