Discussion:
[Qt-creator] 'Open Terminal Here' and login shell on Linux
Andrzej Telszewski
2015-12-08 09:39:00 UTC
Permalink
Hi,

When right-clicking on a file in the project's tree there is an option
to 'Open Terminal Here'.

If I understand correctly, the way the terminal is opened is the following:
1. Change to the directory where the file resides.
2. Execute "Tools -> Options -> Environment -> General -> Terminal" with
the shell executable path appended. In my case it's /bin/bash but I
guess Qt Creator actually takes /bin/sh or reads it from /etc/passwd or
something like that.

My problem is that the shell isn't started as login shell and so the
.profile is not read and I would really like it to do so :)

Can I change it somehow?

My terminal setting for the moment is:
/usr/bin/terminator -x

but I don't think it's relevant as it is the final executable (that is
/bin/bash) that would have to be run with --login argument.

Thanks in advance!

BTW, as I'm new to the list, hello everyone :)
--
Best regards,
Andrzej Telszewski
Hunger Tobias
2015-12-08 11:12:19 UTC
Permalink
Post by Andrzej Telszewski
Hi,
When right-clicking on a file in the project's tree there is an option
to 'Open Terminal Here'.
1. Change to the directory where the file resides.
Yeap.
Post by Andrzej Telszewski
2. Execute "Tools -> Options -> Environment -> General -> Terminal" with
the shell executable path appended. In my case it's /bin/bash but I
guess Qt Creator actually takes /bin/sh or reads it from /etc/passwd or
something like that.
The shell is actually taken from the SHELL environment variable.
Post by Andrzej Telszewski
My problem is that the shell isn't started as login shell and so the
.profile is not read and I would really like it to do so :)
Can I change it somehow?
Only by changing the code:-) Or by playing clever tricks with the terminal
arguments, but I doubt that will work as expected.

Best Regards,
Tobias

--
Tobias Hunger, Senior Software Engineer | The Qt Company
The Qt Company GmbH, Rudower Chaussee 13, D-12489 Berlin
Geschäftsführer: Mika Pälsi, Juha Varelius, Tuula Haataja Sitz der Gesellschaft:
Berlin, Registergericht: Amtsgericht Charlottenburg, HRB 144331 B
Uwe Rathmann
2015-12-09 08:35:01 UTC
Permalink
Post by Hunger Tobias
Post by Andrzej Telszewski
My problem is that the shell isn't started as login shell and so the
.profile is not read and I would really like it to do so :)
Can I change it somehow?
Only by changing the code:-) Or by playing clever tricks with the
terminal arguments, but I doubt that will work as expected.
Sounds like there are initialization in .profile, that should go
to .bashrc. Why not rearranging those initializations instead of trying
to change the rules when they are processed.

Uwe
Andrzej Telszewski
2015-12-09 11:00:55 UTC
Permalink
Post by Uwe Rathmann
Post by Hunger Tobias
Post by Andrzej Telszewski
My problem is that the shell isn't started as login shell and so the
.profile is not read and I would really like it to do so :)
Can I change it somehow?
Only by changing the code:-) Or by playing clever tricks with the
terminal arguments, but I doubt that will work as expected.
Sounds like there are initialization in .profile, that should go
to .bashrc. Why not rearranging those initializations instead of trying
to change the rules when they are processed.
1. Why do you say .bashrc is better than .profile?
2. What I would actually prefer is that /etc/profile (and in consequence
/etc/profile.d) was read. And I guess it's only possible with login
shell (adding --login to /bin/bash would do it).
--
Best regards,
Andrzej Telszewski
Uwe Rathmann
2015-12-09 17:15:08 UTC
Permalink
Post by Andrzej Telszewski
1. Why do you say .bashrc is better than .profile?
There is no good or bad - it is simply, that there are rules, when which
file is read. The basic idea is, that .profile is read once, when you
login, while .bashrc is read, each time you open a bash ( it is similar
for other shells ).

When opening a terminal from the creator it is pretty clear, that you
don't login ( you have been before starting the creator ) and all the
settings from .profile should already be already available ( environment
variables are inherited to child processes ).

So to me it sound more, that you want to initialize your bash in this new
terminal and this would be what .bashrc is made for.

ciao,
Uwe
Andrzej Telszewski
2015-12-09 18:13:52 UTC
Permalink
Post by Uwe Rathmann
Post by Andrzej Telszewski
1. Why do you say .bashrc is better than .profile?
There is no good or bad - it is simply, that there are rules, when which
file is read. The basic idea is, that .profile is read once, when you
login, while .bashrc is read, each time you open a bash ( it is similar
for other shells ).
When opening a terminal from the creator it is pretty clear, that you
don't login ( you have been before starting the creator ) and all the
settings from .profile should already be already available ( environment
variables are inherited to child processes ).
So to me it sound more, that you want to initialize your bash in this new
terminal and this would be what .bashrc is made for.
ciao,
Uwe
OK, it seems there is something to what you say;)

I did the comparison of login and non-login shell environments and they
are exactly the same.

The point is that, I have functions defined in /etc/profile.d/ and
(un)fortunately those aren't inherited by the non-login shells.

My solution for now is to explicitly source selected files from
/etc/profile.d in ~/.bashrc for non-login shells.

It's not the perfect solution, because there are functions I would like
to be defined for all the users at all times.

Unfortunately there don't seem to be a global file that is sourced when
non-login shell is started. This reminds me on why I always was starting
login shells ;)

What I tested and does not work for me:
/etc/bashrc
/etc/bash_profile
/etc/bash.bashrc


Are there any chances that additional settings for Terminal in Qt
Creator could be added?
--
Best regards,
Andrzej Telszewski
Uwe Rathmann
2015-12-10 07:47:49 UTC
Permalink
/etc/bashrc /etc/bash_profile "
man bash:

"When an interactive shell that is not a login shell is started, bash
reads and executes commands from /etc/bash.bashrc then ~/.bashrc when
those files exist and are readable."

If "/etc/bash.bashrc" didn't "work" it is not due to the fact, that it
was not processed and trying to move the same statements to a different
file will probably not change much.

By the way: on my OpenSuse box the standard /etc/bash.bashrc has the
following line: test -s /etc/bash.bashrc.local && . /etc/bash.bashrc.local

What means: create a file /etc/bash.bashrc.local and put your individual
settings there - if you want to avoid, that they get lost with your next
package update.

ciao,
Uwe

PS: but this becomes a bit offtopic on this mailing list
Andrzej Telszewski
2015-12-10 12:17:22 UTC
Permalink
Post by Uwe Rathmann
/etc/bashrc /etc/bash_profile "
"When an interactive shell that is not a login shell is started, bash
reads and executes commands from /etc/bash.bashrc then ~/.bashrc when
those files exist and are readable."
If "/etc/bash.bashrc" didn't "work" it is not due to the fact, that it
was not processed and trying to move the same statements to a different
file will probably not change much.
By the way: on my OpenSuse box the standard /etc/bash.bashrc has the
following line: test -s /etc/bash.bashrc.local && . /etc/bash.bashrc.local
What means: create a file /etc/bash.bashrc.local and put your individual
settings there - if you want to avoid, that they get lost with your next
package update.
I guess my version of bash doesn't take /etc/bash.bashrc into account at
all, it's not even mentioned in the man. My version is: GNU bash,
version 4.3.42(1)-release (x86_64-slackware-linux-gnu)

I'll stick with what is working for me, that is ~/.bashrc.
Post by Uwe Rathmann
ciao,
Uwe
PS: but this becomes a bit offtopic on this mailing list
Yep, it's my last message concerning what bash does or does not ;)
Post by Uwe Rathmann
_______________________________________________
Qt-creator mailing list
http://lists.qt-project.org/mailman/listinfo/qt-creator
--
Best regards,
Andrzej Telszewski
Loading...