Some time ago there was a discussion on the 4OS2 bug tracker about the possibility of a @quoted[] function to quote a variable that contains special characters. I managed to get the same effect with a 'quote' and 'unquote' aliases but they only worked most of the time. So today I decided to try to perfect them. After a lot of trial and error with setdos /x I gave up and decided to just let Rexx do it. Note that the argument is the =name= of the variable, not its value.
setlocal
rem add double quotes to a variable only if it is not already quoted
alias quote=`%@rexx[vv=value('%1',,'os2environment');if left(vv,1) \= '"'|right(vv,1) \= '"' then; %=
vv = '"'||vv||'"';call value '%1', vv, 'os2environment']`
rem strip a pair of double quotes from a variable
alias unquote=`%@rexx[vv=value('%1',,'os2environment');if left(vv,1) == '"'&right(vv,1) == '"' then; %=
vv = substr(vv,2,length(vv)-2);call value '%1', vv, 'os2environment']`
setdos /x-4568
set aa=`<>?/,.\[]|$%^&*()`
echo original:
echo ----- %aa
quote aa
echo quoted by Rexx:
echo ---- %aa
unquote aa
echo unquoted by Rexx:
echo ----- %aa
setdos /x0
Are there any better ideas? Has someone already solved the quote/unquote problem?