Shortcut launcher make bash to not read .bashrc

Bug #1102727 reported by Facundo Batista
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Unity
Invalid
Undecided
Unassigned
unity (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

I always had (well, since around Karmic), a shortcut in my environment, so when I hit ctrl-alt-2, the following snippet would be executed (or very very similar, now adapted to the python 2/3 duality):

  gnome-terminal -t "Python 2" -x bash -c python2

As you can see, this opens a terminal (titled "Python 2") which executes a bash, that executes python2.

Why not make gnome-terminal to execute directly python2? Because as I'm executing bash, it'd read the .bashrc file that sets the PYTHONSTARTUP and PYTHONPATH environment vars. It always worked as I just described.

After I migrated to Quantal this stopped working. It still executes a gnome-terminal, ending in the execution of python2 inside it, but somehow, the .bashrc file is not executed, as the executed Python doesn't have correctly set sys.path.

ProblemType: Bug
DistroRelease: Ubuntu 12.10
Package: unity 6.10.0-0ubuntu2
ProcVersionSignature: Ubuntu 3.5.0-18.29-generic 3.5.7
Uname: Linux 3.5.0-18-generic i686
ApportVersion: 2.6.1-0ubuntu9
Architecture: i386
CompizPlugins: [core,bailer,detection,composite,opengl,decor,mousepoll,vpswitch,regex,animation,snap,expo,move,compiztoolbox,place,grid,imgpng,gnomecompat,wall,ezoom,workarounds,resize,fade,unitymtgrabhandles,scale,session,unityshell]
Date: Mon Jan 21 23:29:59 2013
EcryptfsInUse: Yes
InstallationDate: Installed on 2011-04-19 (644 days ago)
InstallationMedia: Ubuntu 11.04 "Natty Narwhal" - Beta i386 (20110413)
MarkForUpload: True
SourcePackage: unity
UpgradeStatus: Upgraded to quantal on 2012-10-22 (91 days ago)

Revision history for this message
Facundo Batista (facundo) wrote :
Revision history for this message
Omer Akram (om26er) wrote :

Thanks for the bug report. Does it work fine if you just paste that command into a terminal. Does the new terminal window works as you expect doing that?

Changed in unity (Ubuntu):
status: New → Incomplete
Changed in unity:
status: New → Incomplete
Revision history for this message
Facundo Batista (facundo) wrote :

Yes, pasting the whole command in a terminal opens a new gnome-terminal, ends with a Python inside it, and has the correct environments set.

Changed in unity:
status: Incomplete → New
Changed in unity (Ubuntu):
status: Incomplete → New
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Mh, this seems to work here to me.

Revision history for this message
Andrea Azzarone (azzar1) wrote :

Can you still reproduce the bug? Why targeting unity?

Changed in unity:
status: New → Incomplete
Changed in unity (Ubuntu):
status: New → Incomplete
Revision history for this message
Facundo Batista (facundo) wrote :

Yes, this is still broken in Saucy.

Changed in unity:
status: Incomplete → New
Changed in unity (Ubuntu):
status: Incomplete → New
Revision history for this message
Stephen M. Webb (bregma) wrote :

This is the correct behaviour of bash. If you want bash to read its init files as a login session invocation, you need to pass --login (or -l) on the command line. See bash(1). This is not a bug in Unity.

Changed in unity:
status: New → Invalid
Changed in unity (Ubuntu):
status: New → Invalid
Revision history for this message
Facundo Batista (facundo) wrote :

This is not a problem of bash behaviour, it's a problem in the command launcher when you create a shortcut in the environment.

To test it, I created a shortcut with:

    gnome-terminal -t "Python 2" -x bash -l -c python2

(attached to the combination ctrl-alt-2)

Then, I hit ctrl-alt-2, a terminal appeared with the python2 interpreter on it (all ok) but still didn't have the bash environment variables declared in the .bashrc (wrong, which is what this bug is about).

So, I reopened the bug.

Thanks!

Changed in unity:
status: Invalid → New
Changed in unity (Ubuntu):
status: Invalid → New
Revision history for this message
Stephen M. Webb (bregma) wrote :

From the bash(1) man page, under the INVOCATION section:

       When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists.
       After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The
       --noprofile option may be used when the shell is started to inhibit this behavior.

       When a login shell exits, bash reads and executes commands from the file ~/.bash_logout, if it exists.

       When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist. This may be inhibited by using the
       --norc option. The --rcfile file option will force bash to read and execute commands from file instead of /etc/bash.bashrc and ~/.bashrc.

Note that using the -c argument to bash means it's not an interactive shell.

In short, according to the clear and explicit documentation on the bash program, the .bashrc file will not be read under the circumstances in which you're running it.

For additional discussion on how bash handles its startup files, see [1] and especially [2].

If you want a command line to stick in your shortcut that works, try

  gnome-terminal -t "Python 2" -x bash -i -c python2

Since misunderstandings about how to use the bash shell is really not a bug in Unity, I am reclosing this bug.

[1] http://askubuntu.com/questions/121073/why-bash-profile-is-not-getting-sourced-when-opening-a-terminal
[2] http://superuser.com/questions/183870/difference-between-bashrc-and-bash-profile

Changed in unity (Ubuntu):
status: New → Invalid
Changed in unity:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.