0

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)

3
  • 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.) Commented Aug 29, 2011 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
    Commented Aug 29, 2011 at 13:29
  • Yes, it could. (See answer below.) Commented Aug 29, 2011 at 13:34

1 Answer 1

3

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.

3
  • Thank you - so to summarize, I cannot do what I wanted with a KSH script executed in a TCSH shell, right?
    – RonK
    Commented Aug 29, 2011 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. Commented Aug 29, 2011 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. Commented Aug 29, 2011 at 16:12

You must log in to answer this question.

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