1

So I have this bash command:

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}

I want to wrap it manually in my editor. However since it's mostly a string, I can't seem to wrap it with the \ character.

A.k.a, this is not really going to work, 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}

How can I wrap this bash command so that it fits within 100 columns or whatever?

I am looking for something like this:

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}

I have read that adjacent strings should auto-concat, so maybe this works?

   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}
6
  • Can you give an example of what you're looking for? Commented Jun 15, 2017 at 21:18
  • yeah sure np, coming right up Commented Jun 15, 2017 at 21:19
  • 1
    As an aside -- POSIX specifies all-caps names for variables with meaning to the OS or shell, and reserves names with lower-case characters for application use, guaranteeing that lower-case names won't conflict with reserved words meaningful to the OS or shell. See pubs.opengroup.org/onlinepubs/9699919799/basedefs/…, fourth paragraph, keeping in mind that setting a shell variable with a name that conflicts with an existing environment variable will overwrite the latter. Commented Jun 15, 2017 at 21:22
  • 1
    Your last example maybe with a slash at the end? Commented Jun 15, 2017 at 21:23
  • Re: "adjacent strings auto-concat" -- presumably that's in reference to 'foo'"bar"baz, but that's not actually two (or three) adjacent strings at all; it's one string composed with characters quoted in three different styles. Commented Jun 15, 2017 at 21:24

3 Answers 3

5

You don't need anything, in this case at least; SQL can handle newlines in the command without a problem. This should work just fine:

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}"
Sign up to request clarification or add additional context in comments.

Comments

2

Be sure to have nothing after the backslash:

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}

Or, even better (see comments here below):

 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 Comment

Should quote the expansion of $SUMAN_DATABASE_PATH and $SUMAN_DEBUG_LOG_PATH -- otherwise they're vulnerable to splitting on characters in IFS (or, by default, whitespace).
1

I like to use 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

5 Comments

huh but would this work multiple times in the same file? I think not right? idk
@AlexanderMills, without knowing your specific use-case, I would guess that a HEREDOC would work just as well as a string literal.
I thought you could only use one HEREDOC per file
@AlexanderMills, my experience suggests otherwise.
huh, the semantics of EOF (end of file) ... I always assumed you could only have one

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.