4

I'm trying to write a simple script that starts a terminal and runs the command workon foo. In other words, I just want to do:

mate-terminal -e workon foo

However, that doesn't work because the workon command requires me to first do:

export WORKON_HOME=~/work;
source /usr/local/bin/virtualenvwrapper.sh

Normally those lines are run automatically because they're in my .bashrc, but evidently mate-terminal -e doesn't do a source ~/.bashrc. However, if I try adding those lines to my script:

mate-terminal -e export WORKON_HOME=~/work; source /usr/local/bin/virtualenvwrapper.sh; workon foo

it doesn't work either. MATE tells me:

There was an error creating the child process for this terminal
Failed to execute child process "export" (No such file or directory)

I have the same problem if I skip the export and just do mate-terminal -e source ... or if I try to use . instead of source (mate-terminal -e . ...).

I'm not sure how I can load anything if I can't, export, source, or ., but there must be some way because mate-terminal -e would be almost useless without it.

Does anyone know how I can I setup my environment in a terminal started with mate-terminal -e?

2
+50

I do not have a version installed of mate-terminal, but if it works similarly to gnome-terminal you can try one of this ways:

  • to write directly something like
    mate-terminal -e bash -c 'WORKON_HOME=$HOME/work; source /usr/local/bin/virtualenvwrapper.sh; workon foo'
    or
    mate-terminal -e "bash -c 'WORKON_HOME=$HOME/work; source /usr/local/bin/virtualenvwrapper.sh; workon foo; read line'"

    (to be honest in gnome-terminal you should use -x instead of -e).

  • To create your executable script (named WorkOnScript.sh, with chmod u+x WorkOnScript.sh)

    #!/bin/bash 
    WORKON_HOME=$HOME/work;
    source /usr/local/bin/virtualenvwrapper.sh
    cd $HOME/work                                          # If needed
    workon foo
    sleep 10s         # to add  a pause before script and terminal end
    read line         # to wait you press return to close the terminal
    

    and to try to execute it with

     mate-terminal -e /path/to/WorkOnScript.sh
    

    or

     mate-terminal -e "/bin/bash -c \"/path/to/WorkOnScript.sh\""
    

Note

It is possible to keep the terminal open adding as last command in the string passed to bash -c or as last line of the script:

  • for some seconds (or hours...) adding sleep 10s (or sleep 10h).
  • until is pressed return adding read line
  • until ctrl+d or exit is pressed adding /bin/bash (it executes a shell).

With some terminal via parameter specification it possible to keep it open after the execution of the commands. With mate-terminal you can try to see what is interesting from mate-terminal --help-all. After that you have created a profile with "Hold the terminal" checked you can invoke the terminal with the option --window-with-profile=PROFILENAME or --tab-with-profile=PROFILENAME

References

3
  • When I try the first version you provided I got Failed to parse arguments: Unknown option -c. So I then tried the second version, and it worked great ... for about 1ms; after that the terminal closed (presumably because the command is finished). So then I tried the script form, and tried executing it both ways you suggested, but it had the same problem (ie. the terminal closed immediately). If you have any suggestions as to how I can fix the terminal-closing-issue I'll happily accept this answer. Sep 8 '15 at 22:41
  • @machineghost: To avoid the 1ms effect you can put as last line of your script a read line (or a sleep 10s) so that the script will wait you press return to end, (or 10 seconds). You can use the same trick after your command in the string of the bash command ...; workon foo; read line .... In general for many terminal it is possible, see here for example (+), to give a parameter to keep open the terminal. In mate-terminal you can use the profile one ` --window-with-profile` after that you created one as suggested above (+).
    – Hastur
    Sep 9 '15 at 6:49
  • Quick note: I also got a "No module named virtualenvwrapper virtualenvwrapper.sh" error, but I fixed it with the answer found here: stackoverflow.com/questions/29486113/… Sep 30 '15 at 17:28
2

How about you run it in a script?

so create your script:

touch ~/myscript.sh
chmod 700 ~/myscript.sh
vi ~/myscript.sh

then edit it to what you want it to do. In vi use i to insert and be careful of using backspace,use ESC then X to delete. Then do ESC and then !qw to save and exit:

#!/bin/bash
export WORKON_HOME=~/work;
source /usr/local/bin/virtualenvwrapper.sh
mate-terminal -e workon foo

then try and run it:

./myscript.sh
1
  • Thanks for the suggestion, but unfortunately that approach doesn't work. When I run myscript I get No module named virtualenvwrapper virtualenvwrapper.sh: There was a problem running the initialization hooks. I guess the source command in the script doesn't carry over to the new mate-terminal session :( Sep 1 '15 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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