包装bash命令是一个字符串

时间:2017-06-15 21:14:30

标签: bash shell

所以我有这个bash命令:

sqlite3 ${SUMAN_DATABASE_PATH}  "CREATE TABLE suman_run_info (run_id INTEGER, suman_id INTEGER, suite_id INTEGER, test_id INTEGER,
 name TEXT, value TEXT);" >> ${SUMAN_DEBUG_LOG_PATH}

我想在我的编辑器中手动包装它。但是因为它主要是一个字符串,所以我似乎无法用\ _字符包装它。

A.k.a,这不会真正起作用,tmk:

sqlite3 ${SUMAN_DATABASE_PATH}  "CREATE TABLE suman_run_info \ (run_id INTEGER, suman_id INTEGER, suite_id INTEGER, test_id INTEGER,
 name TEXT, value TEXT);" >> ${SUMAN_DEBUG_LOG_PATH}

如何包装此bash命令以使其适合100列或其他任何内容?

我正在寻找类似的东西:

sqlite3 ${SUMAN_DATABASE_PATH}  "CREATE TABLE suman_run_info (run_id INTEGER, 
     suman_id INTEGER, suite_id INTEGER, test_id INTEGER,
     name TEXT, value TEXT);" >> ${SUMAN_DEBUG_LOG_PATH}

我已经读过相邻的字符串应该自动连接,所以这可能有效吗?

   sqlite3 ${SUMAN_DATABASE_PATH}  "CREATE TABLE suman_run_info" 
   "(run_id INTEGER, suman_id INTEGER, suite_id INTEGER, test_id INTEGER,"
     "name TEXT, value TEXT);" >> ${SUMAN_DEBUG_LOG_PATH}

3 个答案:

答案 0 :(得分:5)

你不需要任何东西,至少在这种情况下; SQL可以毫无问题地处理命令中的换行符。这应该可以正常工作:

sqlite3 "${SUMAN_DATABASE_PATH}"  "CREATE TABLE suman_run_info
  (run_id INTEGER, 
   suman_id INTEGER,
   suite_id INTEGER,
   test_id INTEGER,
   name TEXT,
   value TEXT
  );" >> "${SUMAN_DEBUG_LOG_PATH}"

答案 1 :(得分:2)

请确保在反斜杠之后

sqlite3 ${SUMAN_DATABASE_PATH}  "CREATE TABLE suman_run_info \
    (run_id INTEGER, suman_id INTEGER, suite_id INTEGER, \
    test_id INTEGER, name TEXT, value TEXT);" >> ${SUMAN_DEBUG_LOG_PATH}

或者,甚至更好(见下文评论):

 sqlite3 "${SUMAN_DATABASE_PATH}"  "CREATE TABLE suman_run_info \
    (run_id INTEGER, suman_id INTEGER, suite_id INTEGER, \
    test_id INTEGER, name TEXT, value TEXT);" >> "${SUMAN_DEBUG_LOG_PATH}"

答案 2 :(得分:1)

我喜欢使用HEREDOCs

sqlite3 ${SUMAN_DATABASE_PATH} <<EOF  >> ${SUMAN_DEBUG_LOG_PATH}
CREATE TABLE suman_run_info
  (run_id INTEGER, 
   suman_id INTEGER,
   suite_id INTEGER,
   test_id INTEGER,
   name TEXT,
   value TEXT);
EOF