我需要从Fortran
代码中删除文件。我在ubuntu 12.04, x86_64
。我不明白为什么下面描述的过程不起作用。请帮助我澄清情况(实际上,在某些系统上,它有效,但不适用于我的)。
还有另一种方法:我可以直接调用 unix command rm -f file
,但我想知道我的方法有什么问题。谢谢你。
步骤 1. 制作简单的脚本 del.sh 并放入 ~/bin
$ cat del.sh
[ $# -ge 1 ] && rm -f $1
$ chmod u+x del.sh; mv del.sh ~/bin
步骤 2. Fortran 代码,del.for:
character*100 cmd
character*30 file
call getarg(1,file)
write(cmd,100) file
100 format('source del.sh ',a30)
call system(cmd)
end
步骤 3. 编译并运行:
$ ifort -o del del.for
$ ./del file
结果:
sh: 1: source: not found
怎么了?简单的“源 del.sh 文件”有效,但不是来自 Fortran 代码……这令人困惑。
来自 Fortran 代码:
100 format('del.sh ',a30)
100 format('bash del.sh ',a30)
工作完美,但是
100 format('sh del.sh ',a30)
不起作用。我已经bash
安装了,但是没有csh
。谢谢你。