2

I am starting to program in Fortran with gfortran recently on Mac OS X 10.6.8. I wrote the following simple .f90 programs:

sayhi.f90:

subroutine sayhi()
  implicit none
  ! Display output to screen
  print*, 'Hello World'
end subroutine sayhi

and main.f90:

program main
  implicit none
  call sayhi()
end program

When I type the following command in Terminal, the program compiles as expected:

gfortran sayhi.f90 main.f90 -o helloworld.out

However, when I try to use a bash script helloworld.sh:

#!/bin/bash

# Set your compiler (ifort, gfortran, or g95)
# Note: no space before equal sign
F90= gfortran

# Clear old files
rm *.o

# Compile and link (note: variable is used via a $ sign)
$F90 sayhi.f90 main.f90 -o helloworld.out

and type in Terminal

bash ./helloworld.sh

the following error returns:

gfortran: fatal error: no input files
compilation terminated.
rm: *.o: No such file or directory
./helloworld.sh: line 11: sayhi.f90: command not found

I am sure that gfortran is properly installed, since directly inputing the command in Terminal works fine, and all the .f90 and .sh files mentioned above are in the same directory, which is my present working directory. Even if I refrain from using the variable F90 and use the gfortran command directly in the shell file, the same no input files problem occurs.

Could anyone help me identify what the problem is? Many thanks!

4

2 回答 2

3

分配变量时不能在之间添加空格。

F90= gfortran

应该

F90=gfortran.
于 2013-09-02T19:27:36.497 回答
1

改变

# Note: no space before equal sign
F90= gfortran

# Note: no space before OR AFTER the equal sign
F90=gfortran
于 2013-09-02T19:27:38.953 回答