根据没有传递给第一个脚本的参数在 shell 脚本中调用 shell 脚本
Calling shell script inside shell script based on no of arguments passed to first script
我们正在对数据库进行自动化,我们有一个脚本调用 shell 中的另一个脚本。外汇 :-
first-script.sh arg1 agr2 arg3 [Suppose 3 arguments are passed, then we have to call second-script.sh 3 times]
#!/bin/bash
./second-script.sh
./second-script.sh
./second-script.sh
我们怎样才能消除这种依赖?我们想要类似的东西,如果传递了 2 个参数,那么自动第一个脚本应该 运行 like
first-script.sh arg1 agr2
#!/bin/bash
./second-script.sh
./second-script.sh
如果传递了 5 个参数,它应该 运行 像
first-script.sh arg1 agr2 arg3 arg4 arg5
#!/bin/bash
./second-script.sh
./second-script.sh
./second-script.sh
./second-script.sh
./second-script.sh
你只需要遍历参数。
for arg in $@ ; do
second-script.sh "$arg"
done
使用“$@”(也可能是$*)来表示所有参数:
#!/bin/bash
for arg in "$@"
do
./second-script.sh "$arg"
done
我们正在对数据库进行自动化,我们有一个脚本调用 shell 中的另一个脚本。外汇 :-
first-script.sh arg1 agr2 arg3 [Suppose 3 arguments are passed, then we have to call second-script.sh 3 times]
#!/bin/bash
./second-script.sh
./second-script.sh
./second-script.sh
我们怎样才能消除这种依赖?我们想要类似的东西,如果传递了 2 个参数,那么自动第一个脚本应该 运行 like
first-script.sh arg1 agr2
#!/bin/bash
./second-script.sh
./second-script.sh
如果传递了 5 个参数,它应该 运行 像
first-script.sh arg1 agr2 arg3 arg4 arg5
#!/bin/bash
./second-script.sh
./second-script.sh
./second-script.sh
./second-script.sh
./second-script.sh
你只需要遍历参数。
for arg in $@ ; do
second-script.sh "$arg"
done
使用“$@”(也可能是$*)来表示所有参数:
#!/bin/bash
for arg in "$@"
do
./second-script.sh "$arg"
done