[SOLVED] problem with line buffering using here document in bash.
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The problem is that the second shell script doesn't return to the bash prompt after it runs... it requires me to press 'enter' before I get my prompt back. I can't figure out why.
Ok... I just solved my problem by re-directing the here document directly to sqlite3, rather than using 'cat |':
Code:
#!/bin/bash
sqlite3 ~/.timesheet/timesheet.db << query
select
datetime(start_time, 'unixepoch', 'localtime')
, datetime(end_time, 'unixepoch', 'localtime')
, project
, site
, duration
from
timesheet
where
start_time > strftime('%s', 'now', '-1 day', 'localtime');
query
but it's still not clear to me why the former wasn't working.
I believe it's because the << is being applied to the sqllite command and not the cat command, but when the script starts, cat has to do something to pass the control to the sqllite cmd, which is the extra enter that you have to press. If you try ths: cat << query | sqllite.... the script won't wait for an enter. The better solution as you already found out was to remove cat completely. Another solution that I always use is just use the echo command as in your original script, just break it into multiple lines; the shell will handle it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.