I am trying to run an sh (or bash) script that cd into a folder, run a few commands and keep me there so I can start using that terminal. The problem is I can't figure out how to keep me there. the bash command at the end opens the terminal in my home folder instead of /tmp:

xterm -hold -e "cd /tmp && ls && bash" &

I would like to open a few terminals like this since I am working on a project that require multiple terminals (run backend service in one, frontend dev server in the other etc..)

Any ideas?

  • Your command seems to work for me... No idea what might be the difference. Sorry. – Byte Commander Jun 18 '17 at 23:04
  • Perhaps there's something in one of your bash initialization files that cds to your home directory? – steeldriver Jun 18 '17 at 23:21
  • I can even reproduce it just by typing the command in the terminal (without a bash script). I am on 16.04.2 LTS with i3 in case it matters. – roy Jun 19 '17 at 3:19

I solved the issue. I had the following lines in my .bashrc:

PROMPT_COMMAND='pwd > "${HOME}/.cwd"'             # Save current working dir
[[ -f "${HOME}/.cwd" ]] && cd "$(< ${HOME}/.cwd)" # Change to saved working dir

The reason I have them is due to i3. I want i3 to open new terminal in the recent working dir.

I solved the issue by deleting the .cwd file:

xterm -e "cd /tmp && ls && rm ~/.cwd; bash" &

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.