在bash/Shell脚本中调用函数

在bash/Shell脚本中调用函数,bash,shell,Bash,Shell,当我在shell脚本中调用函数时,好像它不工作 testfunction 但如果我调用下面的函数,它就工作了 $(testfunction); 有什么想法吗?我正在Ubuntu上运行bashshell 谢谢,, 桑巴夫 大家好,这里是一个示例脚本和函数decl。然后打电话。如问题中所述,函数调用-函数不起作用,但$(函数起作用) #/bin/bash 头衔=我的头衔”; ########功能 ###函数声明 test(){echo“echo test”;} cat$(cmd)扩展为一个字符串

当我在shell脚本中调用函数时,好像它不工作

testfunction
但如果我调用下面的函数,它就工作了

$(testfunction);
有什么想法吗?我正在Ubuntu上运行bashshell

谢谢,, 桑巴夫

大家好,这里是一个示例脚本和函数decl。然后打电话。如问题中所述,函数调用-函数不起作用,但$(函数起作用)

#/bin/bash
头衔=我的头衔”;
########功能
###函数声明
test(){echo“echo test”;}
cat
$(cmd)
扩展为一个字符串,其中包含执行cmd的结果。它不常与函数一起使用,但可以使用。请参阅此插图,它以两种样式调用函数:

$ cat sample.sh
#!/bin/sh
bla() {
  echo something
}
# print something
bla
# record something
BLA=$(bla)
echo recorded: $BLA
###
$ ./sample.sh
something
recorded: something

根据您的评论,您的问题似乎是与
一起使用的“here document”。请说明如何以及在何处定义函数。“它不起作用。”“这是最糟糕的描述。发生了什么事?你预计会发生什么?答案有什么不同?更重要的是,您显示了错误消息。您不能在“here document”中添加语句。@Sambhav和@Sambhav之间的所有内容都可以显示在您的帖子中。请将其添加到您的问题中,然后您可以将其格式化为可读的格式。键入:
${bla]
应该是
$(bla)
-mine-tooThanks@DavidC.Rankin(实际上是$())太好了,谢谢埃克斯……关于编辑问题而不是评论的建议,我会从下次开始记住。祝你好运,Sambhav
$ cat sample.sh
#!/bin/sh
bla() {
  echo something
}
# print something
bla
# record something
BLA=$(bla)
echo recorded: $BLA
###
$ ./sample.sh
something
recorded: something
echo "this is a string, bla is not recognized as a function"
echo "this is a string, $(bla) executes the function and replaces the output"
cat << EOF
Multi Line
$(bla)
Document
EOF
cat << EOF1
<html><header><titl
<title>test</title></header>
<body>
EOF1
# this section is script code, not here-document
bla
#
cat << EOF2
</body></html>
EOF2