Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 位置不好()';在tcsh中声明函数时_Linux_Shell - Fatal编程技术网

Linux 位置不好()';在tcsh中声明函数时

Linux 位置不好()';在tcsh中声明函数时,linux,shell,Linux,Shell,我试图在tcsh中声明一个函数并调用它 #! /bin/tcsh -f helloWorld () { echo "a" } helloWorld 我得到以下错误: < 512 mews2895 ~/tmp/script> 1.sh Badly placed ()'s. 1.sh 位置不好。 这里有人知道问题出在哪里吗 谢谢请在下面的代码中尝试使用tcsh #! /bin/tcsh -f goto helloWorld helloWorld: echo "a" t

我试图在tcsh中声明一个函数并调用它

#! /bin/tcsh -f

helloWorld () {
    echo "a"
}

helloWorld
我得到以下错误:

< 512 mews2895 ~/tmp/script> 1.sh
Badly placed ()'s.
<512 mews2895~/tmp/script>1.sh
位置不好。
这里有人知道问题出在哪里吗


谢谢

请在下面的代码中尝试使用
tcsh

#! /bin/tcsh -f
goto helloWorld
helloWorld:
echo "a"

tcsh不支持功能

alias helloWorld 'echo "a"'
最佳解决方案:使用一个shell,比如bash

如果出于某种原因必须使用tcsh,别名可以解决眼前的问题,但比函数弱得多

alias helloWorld 'echo "a"'

另一种可能的解决方案是调用单独的脚本。(您必须确保调用的脚本位于
$PATH
中)

tcsh中没有函数。因此,我看到了两种选择:

  • 使用别名:

  • 使用转到。(人们倾向于批评,但这实际上取决于上下文)

如果要使用多个文件组织代码,还有一个选项,请使用源文件

在当前环境中运行shell脚本,而不创建 新建进程时,请使用source命令。您可以运行计算shell 这样编写脚本:源代码计算是否要使用shell 在当前环境中更新变量的脚本,使用 源命令

src:

我认为“使用不同的shell”不应该是一个有效的回答

问候,,
巴勃罗/bin/tcsh-f后面不应该有空格。此外,tcsh没有功能:Ho。。谢谢,我不知道。。Thanks@fedorqui:实际上空格是可选的。@KeithThompson哦,很有趣,很高兴知道。谢谢你的信息!这不是一个函数。没错,不是一个函数,但如上所述,这是一个合理的代理。看起来没有好的选择:(为什么“使用不同的shell”不是有效的响应?它确实解决了问题。