0

Basically I'm running Gaussian09 freqchk utility, I need to write a bash script to interact with the terminal, and I have one variable here(temperature), $i, when I execute the script in terminal, my user argument doesn't seem to be recognizable for somehow reason, and the terminal is just pending for my user argument.

#!/bin/bash
for i in {77..900}
do

freqchk methane.chk > $i
#Write Hyperchem file?
echo "N"
#Temperature (K)?
echo "$i"
#Pressure (Atm)
echo "0"
#Scale factor for frequencies during thermochemistry?
echo "1.0"
#Do you want to use the principal isotope masses?
echo "Y"
#Project out gradient direction?
echo "Y"

done

I have checked with ShellCheck, it doesn't produce any error feedback. I took an answer from Have bash script answer interactive prompts that's why I use echo, but it doesn't seem to work at all. Much appreciated if anyone can spare some hint?

Community
  • 1
  • 1
Gvxfjørt
  • 99
  • 2
  • 7

1 Answers1

0

The full syntax of the freqchk command is:

freqchk checkpoint-file [options] [answers to prompts]

So, in this case the script could be:

#!/bin/bash
for i in {77..900} ; do
    freqchk methane.chk N "$i" "0" "1.0" Y Y > $i
done

That puts it all in a line. Less readable than your commented version. If you really want the comments in you could try something like:

#!/bin/bash
for i in {77..900}
do

grep -v '#' <<EOF | freqchk methane.chk > $i
#Write Hyperchem file?
N
#Temperature (K)?
$i
#Pressure (Atm)
0
#Scale factor for frequencies during thermochemistry?
1.0
#Do you want to use the principal isotope masses?
Y
#Project out gradient direction?
Y
EOF
done

While I'm typing this answer, I think that the question comes from a lack of understanding how in- and output redirection works.

Ljm Dullaart
  • 4,273
  • 2
  • 14
  • 31
  • The first answer is simple and it works great.The 2nd one is more comprehensible, however, it seems several commands were not triggered when I ran through the terminal, perhaps a pending time gap in between each interaction should be considered? But, anyway, the answer is feasible enough, thanks heaps! – Gvxfjørt Oct 15 '16 at 22:21
  • You are right, I have never done any programming before, I started learning bash script, fortran 90/95 and mathematica roughly a month ago due to my new research project, I don't really have time to learn the languages properly, the way how I learn is to deal with more and more cases. – Gvxfjørt Oct 15 '16 at 22:26