简体   繁体   English

将两个参数传递到Shell脚本中

[英]Passing two parameters into shell script

Im very new shell script. 我是一个非常新的Shell脚本。 Im ran the below sqoop command in shell script and got the result. 我在shell脚本中运行了以下sqoop命令,并得到了结果。

sqoop command in shell script Shell脚本中的sqoop命令

#!/bin/bash
while read table; do
sqoop eval --connect jdbc:mysql://127.0.0.1/mydb --username root --password cloudera --query "describe $table"
done<tables.txt

Input file: tables.txt has just one word: MYTAB And Im gettting result for that. 输入文件:tables.txt只有一个词:MYTAB和即时获取结果。

But how can I write a script to take two parameters from the file when data in tables.txt looks like this: MYDB:MYTAB and I want to pass dbname and table name to my sqoop command in the script which looks like below. 但是,当tables.txt中的数据如下所示时,我该如何编写脚本以从文件中获取两个参数:MYDB:MYTAB,我想将dbname和表名传递给脚本中的sqoop命令,如下所示。

#!/bin/bash
while read table; do
sqoop eval --connect jdbc:mysql://127.0.0.1/$dbname --username root --password cloudera --query "describe $table"
done<tables.txt

Can anyone tell me how to extract the values from the file and put them in the file ? 谁能告诉我如何从文件中提取值并将其放入文件中?

在将适当的字段分隔符IFS设置为之后,更改您的read语句:

while IFS=":" read -r dbname table; do

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM