# Ubuntu – Bash script to open up a terminal and cd into a directory

bash

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? #### Best Answer 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.