I am new to bash and trying to run the following command in bash.
name="Na"
for j in {1..3}
do
mkdir $j
cd $j
../../../../../abcinp "$name$j" 1 LennardJones 5.0 30 300 5 30 $j Na
cd ../
done
echo All done
After running this script I need to enter the following parameters
Parameters for atom 0: sigma epsilon >1.24, 1.0
It asks me as many times the loop runs and I need it. Is there a way I can pass these parameters in the script and the script reads it from there? I have not found any clue on this. Any help would be really appreciated.
##updates following meisters suggestion I did the following
#!/bin/bash
./simcode.sh << EOF
1.24 1
1.24 1
1.24 1
When I run the loop three times the parameter 1.24 1 is used for first run only. How can I redirect it for other runs? simcode.sh contains the original script mentioned above.
From what I understand, the program is asking you to type those parameters, because it won't read them as command line arguments. If that is the case, you could try to read from a file (but there's a better option!) like this in your script.sh:
#!/bin/bash
simulationProgram < fileWithArguments.txt
The file "fileWithArguments.txt" should have every argument the program is asking you to type, one per line and in the order the program asks them.
About the better way? Use a heredoc, it's like putting a file inside a file:
#!/bin/bash
simulationProgram << EOF
argument1
...
lastArgument
EOF
anotherCommands # If you need them
The EOF tells bash where the here-doc ends, you can use any word, but be sure that the one after <<
and at the end of the arguments are the same. You can also use bash variables inside the here-doc.
EDIT: I wasn't as clear as I should have been. The heredoc should go in the script with the loop, not in the bash call. Here is what your script should look like, assuming it only asks for 1.24 and 1 each time you run the program (note that 1.24 and 1 are in different lines):
#!/bin/bash
name="Na"
for j in {1..3}
do
mkdir $j
cd $j
../../../../../abcinp "$name$j" 1 LennardJones 5.0 30 300 5 30 $j Na << EOF
1.24
1
EOF
cd ../
done
echo "All done"
What happens inside:
Note: I'm assuming abcinp asks for a parameter, then you press enter, and then asks for another one. If you literally have to type "1.24 1" in the same line, they should be in the same line in your script.