Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm trying to write a simple bash script, which when run from the command line, will cd into a default directory and then open up the folder in the file-browser:

#!/bin/bash

if [ -z "$1" ]
then
  # unless $1 is specified, cd into main proj
  cd code/ruby/my-main-proj
else
  # cd into project specified by $1
  cd code/ruby/$1
fi

# open folder in file manager    
pcmanfm .

This is great, it gives me two things:

  1. a command-prompt whose working directory is set to the project I want
  2. a file-browser for the same project

The trouble is that I would like to run my bash script by clicking on a desktop icon but in it's current form, the terminal does not open up, just the file browser..

So I've made a modification to try and get the terminal to open too:

then
  # unless $1 is specified, cd into main proj
  x-terminal-emulator -e "cd code/ruby/my-main-proj"
else
  # code same as before    

But while the terminal does open, it just displays a blank screen, with no prompt or PWD. How can I get a terminal to open up, and have it's working directory change to the one I'm trying to specify in my bash script?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

I didn't get it to work with x-terminal-emulator, but with the standard gnome terminal.

user@MacBookPro:~$ gnome-terminal --working-directory=~/code/ruby/my-main-proj

Hope this helps.

share|improve this answer
    
ahh, thanks, the --working-directory flag seems to fix this –  marflar Feb 13 '13 at 15:20

Your problem is that you're not executing a shell in your temrinal emulator, you're trying to execute cd, which is a shell command, not an actual shell (not even an actual executable for that matter).

You could make a desktop entry file that starts a shell in a custom working directory, like this:

MyProject.desktop:

[Desktop Entry]
Type=Application
Terminal=true
Exec=x-terminal-emulator
Path=/path/to/code/ruby/my-main-proj
Name=My Project

Note the Path=… above.

share|improve this answer
    
Thanks a lot that helps make sense of a few things –  marflar Feb 13 '13 at 15:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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