0

How can I run "source activate" from a bash script as the -e argument to gnome-terminal?

gnome-terminal -e ". /path/to/virtualenv/bin/activate"

When I run this command, I expect a new terminal that has the command source activate already run. But instead, I get an error in both the current window and the newly created one: Error: Failed to execute child process "." (Permission denied)

I feel like I am making a simple oversight, or misunderstanding the -e argument perhaps.

Running the command in a bash script or a terminal window gives the same result. sudo gives the same result, so I'm thinking the permission issue indicates that I am not doing what I think I'm doing with the command above.

  • Check to see which user owns that directory and try using that user. – user447607 Aug 18 '16 at 19:49
  • same user. But this may be an XY problem, because I am expecting the window to stay open and let me use the terminal as the sourced environment. But doing gt -e "vi" gives me vi, and if i quit, the terminal closes. i may close the question – Rick Page Aug 18 '16 at 20:00
2

That's because the . (source) is a shell-builtin i.e. shell-specific command, not an external one. You need to run it inside shell; Without the shell, gnome-terminal is trying to execute a literal . command with /path/to/virtualenv/bin/activate as its argument, leading to permission denier error.

You need to spawn an interactive shell to do the sourcing and spawn another interactive shell afterwards:

gnome-terminal -e 'bash -ic ". /path/to/virtualenv/bin/activate && bash"'

As you trying to initiate a virtual environment, you might want to set the --rcfile option instead, cleaner approach but the obvious caveat is that the common session startup files /etc/bash.bashrc and ~/.bashrc are not read:

gnome-terminal -e 'bash --rcfile /path/to/virtualenv/bin/activate'

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.