我是个新手。我想执行下面这样的脚本。然而,我得到的错误。请帮我修一下。你知道吗
脚本文件名:测试脚本.sh 执行:/测试脚本.sh“A”
#!/bin/bash
COStesting("Test")
{
if [ $1 = "A" ]
then
Name = "Tiger"
Gender = "Male"
elif [ "$1" = "B" ]
then
Name = "Lion"
Gender = "Male"
fi
}
pass=`python3 - <<END
import subprocess
print(Name, Gender)
END
```
这就是你想要的,包括我和其他人在评论中提到的一些东西。你知道吗
在这里所做的:
注释:Shell script with Python
我所做的只是为
python
命令导出它们,而不是全局导出。[
命令中使用了单=
而不是双==
作为比较运算符pass
是函数中的局部变量。要将其输出,您需要echo
将其从函数输出到标准输出。你知道吗要使用这个函数,您首先
source <filename.sh>
(除非您只是用这个函数将命令附加到文件中),然后可以像$(COStesting "$AorB")
一样使用它,其中$AorB
是包含'A'
或'B'
的变量。你知道吗相关问题 更多 >
编程相关推荐