I'm trying to find a way to translate functions to csh/tcsh aliases, since they lack functions but have parametric aliases. As a first step I'm trying to create an export command.

Here's what I've got so far

alias export 'setenv `echo \!:1 | cut -d'=' -f1` `echo \!:1 | cut -d'=' -f2`'

but I'm baffled as to why it's not working. I'm quite new to their syntax so I might be making a mistake that would be obvious to an experienced (t)csh user. Here's the result:

% export key=value
setenv: Syntax Error.

If I do almost the same thing, but use echo instead of setenv, it works:

alias export 'echo `echo \!:1 | cut -d'=' -f1` `echo \!:1 | cut -d'=' -f2`'
% export key=value
key value

That seems to confirm that everything should work, and it should get translated into setenv key value.

What am I doing wrong?

  • 1
    One problem is you're using single quotes ('), not double quotes ("), the backtick is only executed inside double quotes. So, setenv gets the literal string echo \!:1 | cut -d'=' -f1` `echo \!:1 | cut -d'=' -f2; this is also what echo gets, which parses the backticks, which is why that works :-) ... I don't know how to get it working beyond that, though ... tcsh syntax can be so confusing! Nov 24 '14 at 18:00
alias export 'eval setenv `echo \!:1 | cut -d'=' -f1` `echo \!:1 | cut -d'=' -f2`'
  • 1
    Hi! You could make your answer much more helpful by explaining how it works.
    – dhag
    Dec 4 '15 at 1:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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