2

最近、Mac OS X 10.6.8 で gfortran を使用して Fortran でプログラミングを始めています。.f90以下の簡単なプログラムを書きました。

sayhi.f90:

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

main.f90:

program main
  implicit none
  call sayhi()
end program

ターミナルで次のコマンドを入力すると、プログラムは期待どおりにコンパイルされます。

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

ただし、bash スクリプトを使用しようとすると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

ターミナルに入力します

bash ./helloworld.sh

次のエラーが返されます。

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

ターミナルにコマンドを直接入力しても問題なく動作し、上記のファイル.f90とファイルはすべて同じディレクトリ (現在の作業ディレクトリ) にあるため、gfortran が適切にインストールされていると確信しています。.sh変数の使用を控えて、シェル ファイル内で直接コマンドF90を使用しても、同じ問題が発生します。gfortranno input files

問題が何であるかを特定するのを手伝ってくれる人はいますか? どうもありがとう!

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 に答える