I've never written a shell script before, but I have a web app that needs a whole bunch of things running at once, and it's irritating to have to open each tab, change directories, start my processes, etc.
I'm basing my file on the one shown in this question.
The first chunk (the redis call, which does the cd
on its own) works, sort of - it opens a single terminal tab and runs redis. (I only separated it out for testing purposes; ideally it would be part of the array and all tabs would open in a single terminal window.)
The second chunk is where I'm running into problems. Apparently cd
doesn't work in shell scripts, but that particular link is way over my head, and I don't understand how to implement any of the solutions shown there. The specific error I get is:
bash: cd ~/phoenix/RenderService; npm start: No such file or directory
The tabs that open via the loop have prompts in the redis-stable
directory:
Here's what I want to happen when I run the script:
- Open a terminal window with three tabs, using the Phoenix profile.
- The first tab should change to the
redis-stable
directory, then runsrc/redis-server
- The second tab should change to the
phoenix/PhoenixServices
directory, then runnpm start
- The third tab should change to the
phoenix/RenderService
directory, then runnpm start
The terminal window and all tabs should remain open after the commands have run.
Here's my existing code:
#!/bin/bash
# run redis, PhoenixServices, and RenderService
cd ~/redis-stable
gnome-terminal --tab-with-profile=Phoenix --title=Redis -e 'bash -c "src/redis-server; exec bash"'
tab=" --tab-with-profile=Phoenix"
options=(--tab --title=Terminal)
cmds[1]="'cd ~/phoenix/PhoenixServices; npm start'"
titles[1]="PhoenixServices"
cmds[2]="'cd ~/phoenix/RenderService; npm start'"
titles[2]="RenderService"
for i in 1 2; do
options+=($tab --title="${titles[i]}" -e "bash -c \"${cmds[i]} ; exec bash\"" )
done
gnome-terminal "${options[@]}"
exit 0
Can anyone help a poor newb out?
~/Desktop
just to make it easy to find.tmux
. This would also give you the benefit of not losing context if X-Windows crashes on you.