1
如何操作命令行参数? 例如 如何将字符转换为fortran中的整数?
te.f90
program print_
integer :: i
character(len = 32) :: arg
i = 1
Do
call get_command_argument(i, arg)
if (len_trim(arg) == 0) exit
write(*,*) trim(arg)
write(*,*) trim(arg)**2
i = i + 1
end do
end program print_
te.sh
#!/bin/bash
for ((x = 1; x <=3; x++))
do
./te $x
done
我通过$x
如arg
其类型character
,但我想操纵arg
为数字,当我执行./te.sh
,我得到错误提升Operands of binary numeric operator '**' at (1) are CHARACTER(1)/INTEGER(4)
。
该怎么办?