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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 22:29:19  来源:igfitidea点击:

sh: ...: is not an identifier when trying to invoke shell scripts using plink

bashshellunixplink

提问by arsenal

Below is my shell script that I am trying to execute using PLINKon MachineBfrom MachineA(Windows Machine).

下面是我的shell脚本,我试图用执行PLINKMachineBMachineA(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 plinkto 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 PLINKfrom 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=barsyntax will interpret the string foo=baras 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_OPTSat 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/bashsyntaxis 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 *.shfiles using sh. (You couldconfigure your system, using Folder Options, to invoke *.shfiles using bash, but that might introduce other problems.)

那么系统为什么要用sh调用shell呢?该#!/bin/bash语法特定于类 Unix 系统。Windows 通常根据文件扩展名决定如何执行脚本;显然您的系统配置为*.sh使用 sh调用文件。(您可以使用文件夹选项配置系统以*.sh使用 bash调用文件,但这可能会引入其他问题。)

回答by chepner

I think the -moption to plinkis 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.shis executable by running

test.sh通过运行确保可执行

chmod +x test.sh

on MachineB.

在机器 B 上。