Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

To give more details, the situation is this.

I'm trying to prepare modulefiles (i.e., of the type used by the environment-modules package) to set up environment and aliases for third-party software. Some of the aliases, in particular, are giving me grief. The shell resource files provided by the author -- which I'm hoping to get away from and towards a shell-agnostic environment, hence my interest in modulefiles -- set aliases that incorporate literal curly braces. When I try to put the same string in the modulefile, the contents of the curly braces are expanded.

It seems that in csh/tcsh, the set-alias command of the modulefile is processed and turned into the "alias" command as offered by the shell. This is then processed using eval, as follows:

eval `alias foo 'thing to alias foo to';`

(yes, the trailing semicolon is part of the command).

I can't get away from any of those elements -- the eval, the lack of double quotes around the evaluated string, or the single quotes around the alias text -- without compiling a custom version of modules, which I'm loath to do.

Now, if the alias contains curly braces, I can't see how, in the context of an eval statement, to protect them so they aren't interpreted. I've tried backslashes from here to Timbuktu, I've tried double quotes, I've tried single quotes, I've tried single quotes inside double quotes, I've tried combinations of the above. So far, nothing's worked, and it's bordering on the absurd. Despite extensive Googling, I haven't been able to unearth any answers.

Is there a way to escape the curly braces? If not, let me know, and I'll get on with my life; if so, and it doesn't involve any recompilation, I'd much appreciate any advice. Thanks!

share|improve this question
    
I'm throwing a guess out there, but what about escaped unicode for the curly brace? U+007B and U+007D refer. In fact, there's an SO question that relates: stackoverflow.com/a/5740875/114600 –  user3463 Apr 27 '12 at 3:57
    
Thanks, Randolph, but no luck. If I put the unicode characters in the modulefile, they get "construed" long before they reach the eval command. It looks like the modulefile parser, written in TCL, does that. I found the same thing with the hex strings \x7B and \x7D yesterday. –  Mr Gronk Apr 27 '12 at 4:16
    
Wow, that sucks. –  user3463 Apr 27 '12 at 4:18
add comment

1 Answer

My solution for tcsh/csh is a little verbose. It is to stick "{" into a separate variable.

  set lc="{"
  set rc="}"

I do the same for a dollar sign, which I have trouble escaping. Highly useful for grep regular expressions.

Here's my cut/paste from my .cshrc:

  set dollar = \$

The usage result, like I said, is verbose, but at least works:

> echo "${dollar}${lc}this is inside curlybraces${rc}"
${this is inside curlybraces}

Note that you need those extra quote marks.

Hope this helps!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.