Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我想用 sqlite3将各种bash 脚本的文本保存在我的数据库中。
如果我的脚本这样做
VARIABLE=$(cat "bashScript.sh") sqlite3 mydb.db "CREATE TABLE data (myBash BLOB)" sqlite3 mydb.db "INSERT INTO data VALUES (${VARIABLE})"
因为 bash 脚本将包含所有特殊字符,所以这不起作用。我怎样才能做到这一点?
您需要在 Insert 语句中引用该值,并且您需要保护该值本身的引号:未经测试:
sql_value=$(sed 's/'\''/&&/g' <<< "$VARIABLE") sqlite3 mydb.db "insert into data values ('$sql_value')"