Shell script that open xterm, cd into a folder, run a command, and keeps me there

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:

#!/bin/sh
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?

3

1 Answer

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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like