English 中文(简体)
为什么在设置PatTH LD_LIBRaire_PATH时,该字背着错误。
原标题:Why is this tcsh shell script giving the error while setting PATH LD_LIBRARY_PATH

我制作了一个剪辑,内容如下:

#!/bin/tcsh

setenv PATH  ""
setenv PATH  .:$HOME/bin:/usr/sbin:/usr/bin:/bin:/usr/X11R6/bin:/usr/local/cuda/bin:/usr/local/bin:/usr/bin:$PATH

setenv LD_LIBRARY_PATH ""
setenv LD_LIBRARY_PATH .:/usr/local/cuda/lib:/usr/local/cuda/lib64/:/usr/local/cuda:/usr/lib:/usr/lib32:/usr/local/cuda/bin:/usr/local/lib/:${LD_LIBRARY_PATH}

之后,我已使这一规定得以执行,而且当我试图执行这一规定时,我就这样做了。

./script.sh, it gives following errors:

文字:3:定点:未发现

文字:4: set:没有

文字: 6: 定:无

文字: 7:固定不变

Any pointers, how to set these paths in my shell script?

最佳回答

我的系统没有出现同样的错误。

<>UPDATE>: 关于我最好的猜测,见最后两段。

我最初最好的猜测是,你可以通过改变牧羊来解决这个问题。

#!/bin/tcsh

纽约总部

#!/bin/tcsh -f

(单位:千美元)

#!/bin/csh -f

The features that tcsh adds 纽约总部 the original csh are mostly useful for interactive use rather than scripting.)

The -f option tells tcsh not 纽约总部 process your .login and .cshrc or .tcshrc files when it starts up. Generally you don t want a script 纽约总部 do this; it makes the script s behavior dependent on your own environment setup. Perhaps you have something in your .login that does something odd with setenv, though I can t think of what it might be. Try adding the -f and see if that helps. Even if it doesn t, you should do that anyway.

(-f for /bin/sh or /bin/bashscripts; 这意味着其他东西,也是需要的。)

其他一些意见:

Setting $PATH and $LD_LIBRARY_PATH 纽约总部 the empty string is useless. Just delete those two lines.

http://www.un.org。

On re-reading your question, I see what you re doing there. You set $PATH 纽约总部 the empty string, and then prepend more text 纽约总部 it:

setenv PATH ""
setenv PATH this:that:$PATH

That makes more sense than I thought it did, but it s still simpler 纽约总部 write one command:

setenv PATH this:that

Putting . in your $PATH, especially at the beginning, is a bad idea. Think about what happens if your run the script in a direc纽约总部ry where someone has deposited a command name ls that does something nasty. If you want 纽约总部 execute a command in the current direc纽约总部ry, use ./command. (Putting . at the end of $PATH is safer, but still not a very good idea.)

(And using tcsh or csh as a scripting language (as opposed 纽约总部 an interactive shell) is widely considered 纽约总部 be a bad idea as well. This article, even if it doesn t persuade you 纽约总部 give up on tcsh scripting, will at least make you aware of the pitfalls.)

Oh,如果是用纸面书写,那么你为什么把它称作script.sh? 文档名称上的标记是“不相像的Windows”系统所要求的,但通常需要<代码>。 电话:script.tcsh,或script.csh ,或仅script/code>。

http://www.un.org。

更仔细地研究一下你重新获得的错误信息,从斜线上看,这种错误来自<代码>/bin/sh,not

On my system, when I change setenv 纽约总部 Setenv (a nonexistent command), running the script with tcsh gives me:

Setenv: Command not found.
Setenv: Command not found.
Setenv: Command not found.
Setenv: Command not found.

这与你向我们发出的错误信息相吻合。 当我称之为<代码>/bin/sh foo.tcsh时。 (仅凭<代码>setenv的指挥),我收到:

foo.tcsh: 3: setenv: not found
foo.tcsh: 4: setenv: not found
foo.tcsh: 6: setenv: not found
foo.tcsh: 7: setenv: not found

这与你所发现的错误形式相符。

您说,<代码>/bin/tcsh -version提供了正确结果,从而避免了问题。 有些文字是通过<代码>/bin/sh而不是通过斜体执行。

Here s my best guess about what s going on. You re running on Cygwin, or maybe MSYS, but you re invoking your script from a cmd shell, not from a Cygwin shell. Your Windows system has been configured 纽约总部 recognize a .sh suffix 纽约总部 indicate that the file is a script 纽约总部 be executed by C:cygwininsh.exe (as I mentioned before, file suffixes don t usually matter on Unix, or in the Cygwin environment, but they do on Windows).

The simplest solution would probably be 纽约总部 rewrite the script 纽约总部 conform 纽约总部 Bourne shell syntax. But there should be ways 纽约总部 cause Windows 纽约总部 invoke Cygwin s tcsh 纽约总部 execute it. If I ve guess right, let us know and we can probably come up with a solution.

问题回答

我看不出你的说法有任何错误。 它在我的箱子上课以罚款。

这一错误的唯一原因(我可以认为)是<代码>tcsh,但有些原因没有被用作口译。

I can reproduce the error if I add a line feed before #!/bin/tcsh. When the shebang is not the first chars in the file, the interpreter directive does not take effect and your current shell is used (I m guessing your sheel is not c-shell variant (csh or tcsh)?).

因此,对<代码>#!/bin/tcsh的检查确实是档案中的第一个线,以前没有白色空间。


为了确定实际使用哪位口译人员,试图在你的文字中添加:

echo "$shell"  ## prints shell name if tcsh or csh
echo "$BASH"   ## prints /bin/bash if bash

例如:

[me@home]$ bash x.sh  # run using bash

/bin/bash

[me@home]$ tcsh x.sh # run using tcsh
/bin/tcsh
BASH: Undefined variable.

仅仅打上了这一问题,它被证明是因为有Windows EOLs的文字档案。 一旦清理,所有工作都是好的。





相关问题
What does it mean "to write a web service"?

I just asked a question about whether it was possible to write a web-page-checking code and run it from free web server, and one supporter answered and said that it was possible only if I run "a web ...

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Dynamically building a command in bash

I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...

Why does Scala create a ~/tmp directory when I run a script?

When I execute a Scala script from the command line, a directory named "tmp" is created in my home directory. It is always empty, so I simply deleted it without any apparent problem. Of course, when I ...

Ivy, ant and start scripts

I have a project that uses ant to build and ivy for dependencies. I would like to generate the start scripts for my project, with the classpath, based on the dependencies configured in Ivy, ...

热门标签