1

So I'm trying this command on Bash:

sqlite3 my_db <<! .header on .mode csv select * from table; ! 

It works, but I want to redirect that output to output.csv.

sqlite3 my_db <<! .header on .mode csv select * from table; ! > output.csv 

...but bash seems to think I'm not done with the command:

... $ > $ > $ > ^C $ 

What does Bash want from me? Why can't I get it to redirect the output to my .csv file?

Thanks

2 Answers 2

4

You can do it like this :

sqlite3 my_db <<! > output.csv .header on .mode csv select * from table; ! 

Your last line should contain only the ending characters.

Sign up to request clarification or add additional context in comments.

4 Comments

How does bash know not to include > output.csv as part of the input being redirected?
Sorry if that's a really broad question
If you wanted > output.csv to be part of the input redirected, you would need to escape it like below : sqlite3 my_db <<! \> output.csv (bash would use > as redirection except if escaped)
I like this answer because it preserves the order of input redirection, then output redirection (at least syntactically, even if that's not what Bash does internally)
3

Bash doesn't grossly care what order redirections are specified in if each uses a different FD.

sqlite3 my_db > output.csv <<! ... ! 

2 Comments

That's so confusing. It looks like the input is redirected to the output.csv file itself!
You just need to get used to how the redirection operators work. You can't redirect one file to another in any case; they always apply to the current command. You could even write > output.cv <<! sqlite3 my_db if you wanted to.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.