简体   繁体   English

csh shell脚本疑难解答

[英]csh shell script troubleshooting

i have the following csh shell script thats giving me errors and I'm not quite sure why. 我有以下csh shell脚本,这给了我错误,但我不太确定为什么。 it essentially says that ls and cp commands are not found 它实际上表示找不到ls和cp命令

#!/bin/csh
clear

set path="~/SCRAT_SIMs/V6.0/bin/linux/"
echo "Pushing files to: $path" 

ls packages/

cp -r packages/acte_asym     $path 
cp -r packages/acte_hq/      $path   

when i get rid of the set path then it seems to work. 当我摆脱设置的路径,那么它似乎工作。 any ideas? 有任何想法吗?

In csh and tcsh, the $path shell variable and the $PATH environment variable are tied together. 在csh和tcsh中, $path shell变量和$PATH环境变量绑定在一起。 $PATH (which applies to everything, not just the shell) is a list of directory names separated by : characters. $PATH (不仅适用于外壳,还适用于所有内容)是由:字符分隔的目录名称列表。 $path is a csh array variable that mirrors the contents of $PATH . $path是一个csh数组变量,它镜像$PATH的内容。

In your case, you just need to pick a different variable name. 对于您的情况,您只需要选择一个不同的变量名即可。

If you actually want to manipulate your execution path, you should usually keep the existing contents of $path and add new directories to the beginning or to the end. 如果您实际上要操纵执行路径,通常应该保留$path的现有内容,并在开头或结尾添加新目录。 For example: 例如:

set path = ( ~/bin $path:q )

The :q suffix avoids problems if some directory in $PATH has funny characters like spaces. 如果$PATH某些目录包含空格之类的有趣字符,则:q后缀可避免出现问题。 Note: Don't use double quotes here: 注意:请勿在此处使用双引号:

set path = ( ~/bin "$path" )

That will expand the entire contents of your $path to a single string with embedded spaces; 这样会将$path的全部内容扩展为带有嵌入式空格的单个字符串; $path:q keeps it as an array. $path:q将其保留为数组。

Obligatory link . 强制性链接 (I used to write csh scripts myself, but I've found that sh and bash are much better for programming, though tcsh still has a few advantages for interactive use.) (我以前自己写过csh脚本,但我发现sh和bash对于编程要好得多,尽管tcsh在交互使用方面仍然有一些优势。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM