bash sh: ...: 在尝试使用 plink 调用 shell 脚本时不是标识符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11693405/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
sh: ...: is not an identifier when trying to invoke shell scripts using plink
提问by arsenal
Below is my shell script that I am trying to execute using PLINK
on MachineB
from MachineA
(Windows Machine).
下面是我的shell脚本,我试图用执行PLINK
对MachineB
从MachineA
(Windows计算机)。
#!/bin/bash
export HIVE_OPTS="$HIVE_OPTS -hiveconf mapred.job.queue.name=hdmi-technology"
hive -S -e 'SELECT count(*) from testingtable1' > attachment22.txt
I am using plink
to execute the shell script like below,
我正在plink
用来执行如下的 shell 脚本,
C:\PLINK>plink uname@MachineB -m test.sh
Using keyboard-interactive authentication.
Password:
Using keyboard-interactive authentication.
Your Kerberos password will expire in 73 days.
And this is the below error I always get whenever I try to run like above.
这是我每次尝试像上面一样运行时总是遇到的以下错误。
sh: HIVE_OPTS= -hiveconf mapred.job.queue.name=hdmi-technology: is not
an identifier
Something wrong with my shell script? or some trailing spaces? I am not able to figure it out. I am running PLINK
from windows machine
我的 shell 脚本有问题吗?或一些尾随空格?我无法弄清楚。我正在PLINK
从 Windows 机器上运行
回答by Keith Thompson
The sh:
prefix on the error message indicates that the script is being executed by sh
, not bash
.
该sh:
错误信息上前缀表明该脚本是由执行sh
,而不是bash
。
bash lets you combine setting a variable and exporting it into a single command:
bash 允许您将设置变量并将其导出到单个命令中:
export foo=bar
sh, or at least some older versions of it, require these two actions to be separated:
sh,或者至少是它的一些旧版本,需要将这两个操作分开:
foo=bar ; export foo
A version of sh that doesn't recognize the export foo=bar
syntax will interpret the string foo=bar
as a variable name (and an illegal one, since it isn't an identifier).
无法识别export foo=bar
语法的 sh 版本会将字符串解释foo=bar
为变量名(并且是非法的,因为它不是标识符)。
Either arrange for the script to be executed by bash, or change this:
要么安排脚本由 bash 执行,要么改变这个:
export HIVE_OPTS="$HIVE_OPTS -hiveconf mapred.job.queue.name=hdmi-technology"
to this:
对此:
HIVE_OPTS="$HIVE_OPTS -hiveconf mapred.job.queue.name=hdmi-technology"
export HIVE_OPTS
For that matter, since you're referring to $HIVE_OPTS
at the very beginning of your script, it's almost certainly alreadyexported, so you could just drop the export
.
就此而言,由于您在$HIVE_OPTS
脚本的开头提到了它,因此几乎可以肯定它已经导出,因此您可以删除export
.
(You'll also need to avoid any other bash-specific features.)
(您还需要避免任何其他特定于 bash 的功能。)
So why is the system invoking the shell with sh? The #!/bin/bash
syntaxis specific to Unix-like systems. Windows generally decides how to execute a script based on the file extension; apparently your system is configured to invoke *.sh
files using sh. (You couldconfigure your system, using Folder Options, to invoke *.sh
files using bash, but that might introduce other problems.)
那么系统为什么要用sh调用shell呢?该#!/bin/bash
语法特定于类 Unix 系统。Windows 通常根据文件扩展名决定如何执行脚本;显然您的系统配置为*.sh
使用 sh调用文件。(您可以使用文件夹选项配置系统以*.sh
使用 bash调用文件,但这可能会引入其他问题。)
回答by chepner
I think the -m
option to plink
is for reading commands to execute on the remote machine from a localfile. If my comment about line endings doesn't work, try
我认为-m
选项plink
是从本地文件读取要在远程机器上执行的命令。如果我对行尾的评论不起作用,请尝试
plink uname@MachineB test.sh
Make sure test.sh
is executable by running
test.sh
通过运行确保可执行
chmod +x test.sh
on MachineB.
在机器 B 上。