python - Bash 脚本不处理传递的输入参数

标签 python linux bash shell sh

<分区>

我在跑:

python Parser.py "Bot Pick Nut"

通过 MobaXterm 在 linux 命令行中。这按预期工作,它返回 True。 我面临的问题是当通过 shell 脚本运行时它返回 false?任何人都可以建议为什么我的 shell 没有正确地将结果提供给我的 python 脚本吗?

脚本:

#!/bin/sh
python Parser.py argv[0]

命令:

 ./Shell.sh "Bot Pick Nut"

最佳答案

bash 位置参数$0 开始,$1 是脚本的第一个参数,随后编号来自 $2..$n,其中 $0 是脚本本身的名称。

#!/bin/sh
python Parser.py "$1"

bash 中参数的简单列表,

$0              the first positional parameter, equivalent to argv[0] in C, see the first argument
$FUNCNAME       the function name (attention: inside a function, $0 is still the $0 of the shell, not the function name)
$1 … $9        the argument list elements from 1 to 9
${10} … ${N}   the argument list elements beyond 9 (note the parameter expansion syntax!)
$*              all positional parameters except $0, see mass usage
$@              all positional parameters except $0, see mass usage
$#              the number of arguments, not counting $0

关于python - Bash 脚本不处理传递的输入参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43138655/

相关文章:

python - 在 sklearn 中使用 RandomForestClassifier 进行不平衡分类

python - 创建一个简单的 Python 联系表单

python - Pytorch - 如何区分两个参数

bash - 如何在 shell 脚本中使用 unset 和 xargs?

python - 带 GUI 的 Pi 相机预览 - Raspberry Pi

linux - 终端仅显示 $

c - Linux/Unix 作为内核运行

linux - 如何过滤 ls 命令的输出以仅显示二月份创建的文件?

regex - 如何使用awk忽略空行和注释行

bash - POSIX shell 等效于 <()