Question

I'm trying to update some scripts from tcsh to bash to reflect the bash preference of some users. Needless to say, I don't know csh. Can someone tell me what this line does?

alias prepend 'if (-d \!:2) if ("$\!:1" \!~ *"\!:2"*) export \!:1 "\!:2":${\!:1}'
Was it helpful?

Solution

That probably prepends a directory onto a variable if said directory doesn't already exist in said variable.

Here's what it says, in English: if the second argument is a directory, then if the first argument interpreted as a variable does not contain the text of the second argument, then "export" the string "second argument colon contents of first argument" into the first argument.

It all depends upon what export does. In my experience, export is an alias for setenv, but that is not guaranteed.

I would suggest a test to see if this does what I think. First, echo your path. Then run prepend PATH /a/new/directory/that/exists. Then echo your path again. If you see that "/a/new/directory/that/exists" is now in your path variable, then you can be reasonably sure export is an alias for setenv.

Finally, this SO post lists strategies to implement a similar thing in other languages and shells.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top