linux - 基于没有传递给第一个脚本的参数在 shell 脚本中调用 shell 脚本
问题描述
我们正在对数据库进行自动化操作,其中一个脚本在 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 $1
./second-script.sh $2
./second-script.sh $3
我们怎样才能消除这种依赖呢?我们想要这样的东西,如果传递了 2 个参数,那么第一个脚本应该自动运行
first-script.sh arg1 agr2
#!/bin/bash
./second-script.sh $1
./second-script.sh $2
如果传递了 5 个参数,它应该像这样运行
first-script.sh arg1 agr2 arg3 arg4 arg5
#!/bin/bash
./second-script.sh $1
./second-script.sh $2
./second-script.sh $3
./second-script.sh $4
./second-script.sh $5
解决方案
你只需要遍历参数。
for arg in $@ ; do
second-script.sh "$arg"
done
推荐阅读
- java - 在 RxJava/RxAndroid 中的 observables 之间传递响应
- vue.js - Vue.js 父子组件,为什么我的 prop 在子组件中还没有?
- networking - Vagrant 私网固定ip
- bash - 从文本文件中的两个列表组合 bash 中的键值对
- ssas - MDX 查询以获取去年的数据,而不根据当前月份进行过滤
- r - Rjsonio vs jsonlite 词法错误
- apache-nifi - NiFi FlowFile 存储库更新失败
- html - 如何使用 Angular js 在花括号中执行 html 代码
- spring-boot - springboot控制器如何接收有限的字符串?
- vue.js - 如何在 Nuxt.js 中为多个主机创建环境变量?