Quote an argument for the host shell, escaping embedded quotes as needed.
" is doubled.' is escaped using a standard ' → '"'"' pattern.| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | a |
function quote_arg(a) result(q) character(len=*), intent(in) :: a character(len=:), allocatable :: q if (is_windows_os()) then q = '"' // escape_quotes_win(trim(a)) // '"' else q = "'" // escape_quotes_sh(trim(a)) // "'" end if contains pure function escape_quotes_win(s) result(r) character(len=*), intent(in) :: s character(len=:), allocatable :: r integer :: j r = "" do j = 1, len_trim(s) if (s(j:j) == '"') then r = r // '""' else r = r // s(j:j) end if end do end function escape_quotes_win pure function escape_quotes_sh(s) result(r) character(len=*), intent(in) :: s character(len=:), allocatable :: r integer :: j r = "" do j = 1, len_trim(s) if (s(j:j) == "'") then r = r // "'""'""'" else r = r // s(j:j) end if end do end function escape_quotes_sh end function quote_arg