Skip to content

Commit 1d10896

Browse files
committed
updated multiple script
1 parent 8262afc commit 1d10896

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

docs/source/oar.rst

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,38 @@ If one wants to launch the current job, one simply have to type:
7777
oarsub -S ./sub.sh
7878
7979
and a single job with name *lmp-myvariable-0* will be send.
80-
To launch multiple simulations with different values of *myvariable*, one
81-
can create a second bash script containing:
80+
To launch multiple simulations with different values of *myvariable*,
81+
say 0, 1, and 2, one can create a second bash script, named *multi-sub.sh*,
82+
and containing:
8283

8384
.. code:: bash
8485
8586
#!/bin/bash
86-
set -e # Exit immediately if error
87+
set -e
8788
88-
# Loop over a desired set of values for myvariable
8989
for myvariable in 0 1 2
9090
do
91-
# Create a new line that will replace the line containing `myvariable` in the script sub.sh
91+
# deal with OAR -n
92+
newline='#OAR -n lmp-myvariable-'$myvariable
93+
oldline=$(cat sub.sh | grep '#OAR -n lmp-myvariable-')
94+
sed -i '/'"$oldline"'/c\'"$newline" sub.sh
95+
# deal with myvariable
9296
newline='myvariable='$myvariable
93-
# Find the current line in sub.sh that contains 'myvariable =', storing it in the variable oldline
94-
# This assumes there is exactly one such line, otherwise the behavior may be unexpected
9597
oldline=$(cat sub.sh | grep 'myvariable =')
96-
# Use sed to replace the old line with the new line (newline) in sub.sh
97-
# This command searches for the line containing the value in oldline and replaces it with newline
9898
sed -i '/'"$oldline"'/c\'"$newline" sub.sh
9999
chmod +x sub.sh
100100
oarsub -S ./sub.sh
101101
done
102+
103+
The *newline* command creates a new line that will replace the line
104+
containing *myvariable* in the script sub.sh
105+
The *oldline=* command finds the current line in sub.sh that contains 'myvariable =',
106+
storing it in the variable oldline. This assumes there is exactly one such line,
107+
otherwise the behavior may be unexpected. Then, sed is used to replace the old
108+
line with the new line (newline) in *sub.sh*.
109+
110+
Then, simply run *multi-sub.sh* by typing:
111+
112+
.. code:: bash
113+
114+
bash multi-sub.sh

0 commit comments

Comments
 (0)