我想从没有运气的提示输入选项中分配一个变量。如果用户输入1,我想要target_db_name =“database2”。 我的代码:将变量赋值给if语句中的一个变量
while true; do
read -p "What is the table name?" table_name
table_name=${table_name,,}
if hdfs dfs -test -e /foo/$table_name ;
then read -p "What is the target database you want to copy the
“foo.${table_name}” table to?
Your three options are:
1) database1
2) database2
3) database3
Type 1, 2, or 3: " target_db;
(((Here is where I want to state if $target_db = "1" then target_db_name
= "database1", if $target_db = "2" then target_db_name = "database2" etc...)))
read -p "Would you like to begin the HDFS copy with the following configuration:
Target Database: ${target_db_name}
Table Name: ${table_name}
Continue (Y/N):"
else echo "Please provide a valid table name.
Exiting this script" ; exit ; fi
done
我试图if语句,没有运气创建另一个。
"....Type 1, 2, or 3: " target_db;
else if $target_db = "1" then target_db_name = "edw_qa_history"; fi
请显示你的尝试,所以我们可以解释你做错了什么。 – Barmar
请记住'bash'中的变量赋值在'='周围没有空格。 – Barmar
而且你应该使用'case'而不是'if'。 – Barmar