[SOLVED] bash: [ -t 0 ] does return false if script is piped into bash on the console
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
I hope this helps AND gives you a clue as to where to find out more.
I see. I thought the interactive property is inherited by subshells. But frankly I have no clue where to search and which keyword to use to find a solution for my issue.
Quote:
Originally Posted by computersavvy
Nice code change. But this doesn't help me at all :-(
Now I had a look at your previous post.
If you must feed it by a program (curl, not cat) then try to run the shell in the foreground (and the program in the background).
I see. I thought the interactive property is inherited by subshells. But frankly I have no clue where to search and which keyword to use to find a solution for my issue.
No, that is not possible. Every invocation of bash can (and will) decide if it was started in interactive mode - by itself. Interactive mode also assumes there is a real input (keyboard) attached to that bash.
Subshells and other scripts which are just executed are not interactive shells, and that is the intended way (especially when the input and output are connected to pipes)
Quote:
Originally Posted by framp
Unfortunately I now need a way to pass the interactive property down to the called script.
You must not do that. You need to redesign your script. As it was suggested by MadeInGermany you can avoid starting a subshell, but in some cases it does not help (obviously it depends on your script).
The pipe hides the original input.
Also there is useless use of cat.
The following solves both:
Code:
< t.sh bash -s -- -1
Thank you very much for your answers. They are very interesting. Now I have something to test and to work with :-)
As far as I can see right now I have to redesign the code (suggested by @pan64) and solve the issue with an invocation parameter to signal the script is running in interactive mode (that's what I think @comutersavvy suggested with his code change - sorry I didn't catch this yesterday) because I detected the called script also uses
Code:
BASH_SOURCE[0]
to extract the directoryname of the script but this is empty if the script is piped into bash. Or I have to find a way to remove the usage of
Code:
BASH_SOURCE[0]
.
Thank you very much to everybody for your help. I now know which alternatives I have and will choose one of them :-)
I detected other issues which are related to the way the called script works with stdin, stdout and stderr :-(. Therefore I decided to split everything into two commands: One which downloads the script and the other which calls the downloaded script with sudo.
Again: Thank you very much for your comments and help.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.