我想從沒有運氣的提示輸入選項中分配一個變量。如果用戶輸入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