Retrieve a command-line argument as an allocatable string.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | i |
0-based/1-based index passed to |
function get_arg(i) result(a) integer, intent(in) :: i !! 0-based/1-based index passed to `get_command_argument`. character(len=:), allocatable :: a integer :: n, istat n = 0 call get_command_argument(i, length=n, status=istat) if (istat /= 0 .or. n <= 0) then a = "" return end if allocate(character(len=n) :: a) call get_command_argument(i, value=a, status=istat) if (istat /= 0) a = "" end function get_arg