[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Better shell_quote() function for included shellquote.awk
From: |
Nikita Zlobin |
Subject: |
Better shell_quote() function for included shellquote.awk |
Date: |
Sat, 26 Aug 2023 03:31:03 +0300 |
I could not find, how to submit via savannah, so sending there.
Current shell_quote() code, posted in info docs and available for include,
seems a bit primitive. I enhanced it for minimized quoting, as I would do when
e.g. inlining long awk code in shell script. My version uses greedy regexp for
separators, thus requiring to get separators array from split().
##########################
function shell_quote(s, # parameter
Q,q,b, n,i, X,S, ret) # locals
{
if (! s)
return "''"
Q = "\x27" # single quote
q = "\x22" # double quote
b = "\x5c" # backslash
n = split(s, X, "([^" q b b "]*" Q "+[^" q b b "]*)+", S)
for (i = 1; ;i++) {
if (X[i])
ret = ret Q X[i] Q
if (i == n)
break
ret = ret q S[i] q
}
return ret
}
##########################
--
Nikita Zlobin
- Better shell_quote() function for included shellquote.awk,
Nikita Zlobin <=