【问题标题】:If loop not working properly如果循环不能正常工作
【发布时间】:2017-11-30 09:29:42
【问题描述】:

在我的脚本中,当第一次在 if 循环中执行时,我在第三次执行后无法正常执行时正确执行。如果有任何错误,我该怎么办啊...?请解决我的问题...?在脚本中,我将客户名称的值设为 ABC,然后我再次给了 ABC,它正确执行了 if 条件,但我第三次给了 ABC,因为它无法正常工作..!

#!/bin/bash

echo " --- Enter the Database name ---"
read databasename


echo " --- enter the table name --- "
read table_name

sqlite3 $databasename.db "DROP TABLE IF EXISTS $table_name;"

sqlite3 $databasename.db  "CREATE TABLE IF NOT EXISTS $table_name(cus_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,cus_name TEXT NOT NULL UNIQUE ,cus_domain TEXT UNIQUE, cus_status TEXT NOT NULL,Port INTEGER NOT NULL);"


echo " --- Enter the total number of rows do you want ---"
read cus_count


echo "--- Enter the following details one by one---"

port_num=8080

for((i=1;i<=cus_count;i++))
do


echo "enter the $i customer details"

echo "---Enter the customer name---"
read c_name

customer=$(sqlite3 $databasename.db "select cus_name from $table_name")



if [[ "$port_num" == "$port_num" ]]; then
port_num=$(($port_num + 1))
fi


if [[ $c_name != $customer ]]
then
    echo "---Enter the Status(Active/Inactive)---"
    read c_status



c_domain="$c_name"

else
    echo "---OOPS you entered customer name already available---"
    echo "---Please enter new customer name---"

i=$(($i - 1))

fi

sqlite3 $databasename.db "INSERT OR IGNORE INTO $table_name (cus_name,cus_domain,cus_status, Port) VALUES(\"$c_name\",\"${c_domain,,}.com\",\"$c_status\",\"$port_num\") ;" 


done

echo " --- Records from the $table_name ---"

sqlite3 $databasename.db "select * from $table_name;"

【问题讨论】:

  • 我发现了问题..它只检查 cus_name 最近的值,因此它不能正常工作。如果它检查完整的 coulumn 值,它会正确执行。我如何检查脚本中的完整 coulmn。 .?

标签: bash shell variables


【解决方案1】:

【讨论】:

  • 我解决了这个问题
  • 我发现了问题..它只检查 cus_name 最近的值,因此它不能正常工作。如果它检查完整的 coulumn 值,它会正确执行。我如何检查脚本中的完整 coulmn。 .?
猜你喜欢
  • 1970-01-01
  • 2021-03-01
  • 2012-01-02
  • 2015-05-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多