Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a KSH script that exports an environment variable (export SOME_VAR=123)

After running the script my current shell is unaffected and echo $SOME_VAR produces nothing.

I tried running . myScript.ksh but got the following error:

.: Permission denied.

Permissions for . are drwxr-xr-x

Any idea? (I'm not root)

share|improve this question
    
What permissions does myScript.ksh have? Is it readable? (Using . name is the correct way, since a process cannot update its parent's environment, which is why running the script "as a script" did not work.) – grawity Aug 29 '11 at 13:18
    
The script's permissions are -rwxr-xr-x - and it runs when invoking it without . before it. Can it be related to the fact my shell is TCSH? – RonK Aug 29 '11 at 13:29
    
Yes, it could. (See answer below.) – grawity Aug 29 '11 at 13:34
up vote 3 down vote accepted

You are using tcsh as your shell:

  1. tcsh does not have a . command – only source.

    > source myScript.ksh
    

    In sh, ksh and bash shells, "." is a built-in command, unrelated to the "current directory" usage of "."

    In csh and tcsh, no such built-in exists (the equivalent is named "source"), and using . will attempt to execute a directory, hence the "Permission denied" error.

  2. tcsh is a csh derivative, and uses a very different syntax for setting environment variables:

    setenv SOME_VAR 123
    

    This matters because using ./source causes the file's contents be executed in the current shell, meaning they have to be valid tcsh syntax.

share|improve this answer
    
Thank you - so to summarize, I cannot do what I wanted with a KSH script executed in a TCSH shell, right? – RonK Aug 29 '11 at 14:31
    
@RonK: Right. If you want to change enviroment variables of your current shell, you have to use . or source, and for that you must use a script written specifically for your current shell. – grawity Aug 29 '11 at 16:10
    
@RonK: There is another possibility — write a script, in any language that outputs (echo's) the apropriate setenv lines, then tell tcsh to evaluate that script's output: eval `./myscript`; this is somewhat fragile, though — you have to be very careful with output quoting. – grawity Aug 29 '11 at 16:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .