I'm trying to write a bash script to create a screen (software) session with a specific set of windows, and cd to specific directories on each one.
Here is the script I have so far:
#!/bin/bash
killall screen;
screen -AmdS work;
screen -S work bash -c "cd myDir";
The problem is that I can't seem to change directories on that session. After running this script, I run $ screen -r and the current directory is still my default directory (~/).
(I've tried changing the cd command to touch myFile and the file is there after I run the script)
bash -c "cd myDir"in your terminal, you'll see that it doesn't change directories. Use the screen command (not shell command)chdirto change directories, then open a new shell and it will start in that directorybashcommand, not the directory of the shell/program that ran it. And since that new shell is exiting as soon as it finishes running the script it was passed withbash -c...