I'm not a programmer, just a chemist. I'm writing a bash script, which I want to run on the server and expect it to do the following:
- Open a terminal
- Loop over folders
slave_1
,slave_2
, ...,slave_N
for each folder open a tab, start up MATLAB (maltab -nodesktop
), cd to the folder, and run the scriptslave_process
.
Here is what I have so far:
#!/bin/bash
for i in {1..5}
do
gnome-terminal --tab --working-directory="/usr/local/MATLAB/MATLAB_Production_Server/R2015a/bin" --command='./matlab -nodesktop; cd /mnt/projects/slave_$i; -nosplash -r slave_process'
done
exit 0
Can some help me to get the script to work? I'm not in the sudoers file, so can't change anything on the server.
Update. The answer by @muru does the trick but it starts a new terminal at each loop iteration, which is a pain since I need to run around 200 MATLAB instances. I want to have multiple tabs in the same terminal (or no terminal at all is fine as well). Here is my modified code, which does not work:
args=()
for i in {1..5}; do
cmd=working-directory='/mnt/projects/slave_$i' --command='/usr/local/MATLAB/MATLAB_Production_Server/R2015a/bin/matlab -nodesktop -nosplash -r slave_process'
args+=(--tab-with-profile=Default -e "sh -c \"$cmd; bash\"")
done
gnome-terminal "${args[@]}"
Can someone help here?