你如何简化并给这个shell脚本一个漂亮的外观?也许使用循环等..
#!/usr/bin/env bash
echo 'Testing 1'
CONF_PATH=/var/..../test_1 python27 -m unittest test1
CONF_PATH=/var/..../test_1 python27 -m unittest test2
CONF_PATH=/var/..../test_1 python27 -m unittest test3
CONF_PATH=/var/..../test_1 python27 -m unittest test4
CONF_PATH=/var/..../test_1 python27 -m unittest test5
CONF_PATH=/var/..../test_1 python27 -m unittest test6
echo 'Testing 2'
CONF_PATH=/var/..../test_2 python27 -m unittest test1
CONF_PATH=/var/..../test_2 python27 -m unittest test2
CONF_PATH=/var/..../test_2 python27 -m unittest test3
CONF_PATH=/var/..../test_2 python27 -m unittest test4
CONF_PATH=/var/..../test_2 python27 -m unittest test5
CONF_PATH=/var/..../test_2 python27 -m unittest test6
答案 0 :(得分:1)
只做一个双循环
for i in 1 2
do
echo "Testing $i"
for j in 1 2 3 4 5 6
do
CONF_PATH=/var/..../test_$i python27 -m unittest test$j
done
done
答案 1 :(得分:0)
只需将你的命令插入回音所在的位置即可。
#!/usr/bin/env bash
TESTGROUPS=$1
TESTS=$2
# Loop groups
for i in `seq 1 $TESTGROUPS`
do
echo "TESTGROUP $i"
# Loop tests
for j in `seq 1 $TESTS`
do
echo "TEST $j"
done
done
用
执行./test.sh 2 3
会导致
TESTGROUP 1
TEST 1
TEST 2
TEST 3
TESTGROUP 2
TEST 1
TEST 2
TEST 3