最近、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
を使用しても、同じ問題が発生します。gfortran
no input files
問題が何であるかを特定するのを手伝ってくれる人はいますか? どうもありがとう!