<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Committed, thanks!<div class=""><br class=""></div><div class="">christos<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Nov 12, 2021, at 10:46 AM, H.Merijn Brand <<a href="mailto:tcsh@tux.freedom.nl" class="">tcsh@tux.freedom.nl</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta charset="UTF-8" class=""><div class="content-isolator__container" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div class="protected-part"><div class="protected-title">Signed PGP part</div><div class="protected-content">On Fri, 12 Nov 2021 16:32:42 +0100, "H.Merijn Brand" <<a href="mailto:tcsh@tux.freedom.nl" class="">tcsh@tux.freedom.nl</a>> wrote:<br class=""><br class=""><blockquote type="cite" class="">If I have an environment variable that is to contain something Unicodish,<br class="">I currently have to to something similar to<br class=""><br class="">% setenv EURO_CH `perl -CO -e'print "\N{EURO SIGN}"'`<br class="">or<br class="">% setenv EURO_CH `perl -CO -e'print "\x{20ac}"'`<br class=""><br class="">so this works<br class="">% echo $EURO_CH<br class="">€<br class=""><br class="">I browsed the tcsh manual, but could not find anything that would hint<br class="">to doing this natively. Is there a (hidden) feature to set Unicode<br class="">characters from the command line by their name or hex value (in the<br class="">current encoding)? Something similar to<br class=""><br class="">% setenv EURO_CH "\x{20ac}"<br class="">% setenv EURO_CH "\u20AC"<br class=""><br class="">In my digging, I found that<br class=""><br class="">% setenv TAB_CH "\t"<br class=""><br class="">just sets the environment variable TAB_CH to a literal '\' followed by<br class="">a 't'. Which was kinda surprising to me, as I expected a TAB to be in<br class="">there as a literal TAB. That was done in echo in sh.func.c, so<br class=""><br class="">% echo $TAB_CH<br class=""><br class="">translated \t to TAB. To do the same for \x{20ac}, \xbf, and \u0020ac<br class="">I changed sh.func.c like below, but I eventually want those escapes<br class="">to end up literally in the environment. Thoughts welcome<br class=""><br class="">--8<---<br class="">diff --git a/sh.func.c b/sh.func.c<br class="">index cdfb6d8d..cbc4ff41 100644<br class="">--- a/sh.func.c<br class="">+++ b/sh.func.c<br class="">@@ -1196,6 +1196,22 @@ doglob(Char **v, struct command *c)<br class="">    flush();<br class="">}<br class=""><br class="">+static Char<br class="">+parse_hex_range(Char **cp, int l)<br class="">+{<br class="">+    int  ui = 0;<br class="">+    char ub[9];<br class="">+<br class="">+    if (l > 8) return 0; /* Unsupported length */<br class="">+<br class="">+    while (**cp && ui < l && isxdigit(**cp)) {<br class="">+       ub[ui++] = (char)**cp;<br class="">+       (*cp)++;<br class="">+    }<br class="">+    ub[ui] = (char)0;<br class="">+    return strtol (ub, NULL, 16);<br class="">+}<br class="">+<br class="">static void<br class="">xecho(int sep, Char **v)<br class="">{<br class="">@@ -1289,6 +1305,28 @@ xecho(int sep, Char **v)<br class="">                   if (*cp >= '0' && *cp < '8')<br class="">                       c = c * 8 + *cp++ - '0';<br class="">                   break;<br class="">+               case 'x':<br class="">+                   if (*cp == '{' && isxdigit(*(cp + 1))) { /* \x{20ac} */<br class="">+                       cp++;<br class="">+                       c = parse_hex_range (&cp, 8);<br class="">+                       if (*cp != '}')<br class="">+                           stderror(ERR_NAME | ERR_VARBEGIN);<br class=""></blockquote>    This needs a proper new error message of course<br class=""><br class=""><blockquote type="cite" class="">+                       cp++;<br class="">+                   }<br class="">+                   else if (isxdigit(*cp)) {   /* \x9f */<br class="">+                       c = parse_hex_range (&cp, 2);<br class="">+                   }<br class="">+                   else /* backward compat */<br class="">+                       xputchar('\\' | QUOTE);<br class="">+                   break;<br class="">+               case 'u':<br class="">+                   if (isxdigit(*cp)) {        /* \u0020ac */<br class="">+                       c = parse_hex_range (&cp, 6);<br class="">+                   }<br class="">+                   else /* backward compat */<br class="">+                       xputchar('\\' | QUOTE);<br class="">+                   break;<br class="">+<br class="">               case '\0':<br class="">                   c = '\\';<br class="">                   cp--;<br class="">-->8---  <br class=""></blockquote><br class="">And a demo of course<br class=""><br class="">% unsetenv EURO<br class="">% echo $EURO<br class="">EURO: Undefined variable.<br class=""><br class="">% setenv EURO "\u20ac"<br class="">% env | grep EURO<br class="">EURO=\u20ac<br class="">% echo $EURO<br class="">€<br class=""><br class="">% setenv EURO `echo "\u20ac"`<br class="">% env | grep EURO<br class="">EURO=€<br class="">% echo $EURO<br class="">€<br class=""><br class="">--<span class="Apple-converted-space"> </span><br class="">H.Merijn Brand  <a href="https://tux.nl/" class="">https://tux.nl</a><span class="Apple-converted-space"> </span>  Perl Monger   <a href="http://amsterdam.pm.org/" class="">http://amsterdam.pm.org/</a><br class="">using perl5.00307 .. 5.33        porting perl5 on HP-UX, AIX, and Linux<br class=""><a href="https://tux.nl/email.html" class="">https://tux.nl/email.html</a><span class="Apple-converted-space"> </span><a href="http://qa.perl.org/" class="">http://qa.perl.org</a><span class="Apple-converted-space"> </span><a href="https://www.test-smoke.org/" class="">https://www.test-smoke.org</a><br class=""><br class=""></div></div><br class=""><iframe class="content-isolator__isolated-content" sandbox="allow-scripts" scrolling="auto" width="200" height="10" data-src="data:text/html;charset=UTF-8;base64,PGlmcmFtZS1jb250ZW50IGRhdGEtaWZyYW1lLWhlaWdodD0idHJ1ZSI+LS0gPEJSPlRjc2ggbWFpbGluZyBsaXN0PEJSPlRjc2hAYXN0cm9uLmNvbTxCUj5odHRwczovL21haWxtYW4uYXN0cm9uLmNvbS9tYWlsbWFuL2xpc3RpbmZvL3Rjc2g8QlI+PC9pZnJhbWUtY29udGVudD4=" src="data:text/html;charset=UTF-8;base64,PGlmcmFtZS1jb250ZW50IGRhdGEtaWZyYW1lLWhlaWdodD0idHJ1ZSI+LS0gPEJSPlRjc2ggbWFpbGluZyBsaXN0PEJSPlRjc2hAYXN0cm9uLmNvbTxCUj5odHRwczovL21haWxtYW4uYXN0cm9uLmNvbS9tYWlsbWFuL2xpc3RpbmZvL3Rjc2g8QlI+PC9pZnJhbWUtY29udGVudD4=" style="border: none; display: block; overflow: auto;"></iframe></div><br class="Apple-interchange-newline"></div></blockquote></div><br class=""></div></body></html>