This question already has an answer here:
- Converting character string to integer 2 answers
How to manipulate the command line argument? for example
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
I pass $x
as arg
which has type character
, but I want to manipulate arg
as a number, when I execute ./te.sh
, I got the error promotion Operands of binary numeric operator '**' at (1) are CHARACTER(1)/INTEGER(4)
.
what to do?
You'll need to convert the string (arg) into an integer.