Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash sh:…:在尝试使用plink调用shell脚本时不是标识符_Bash_Shell_Unix_Plink - Fatal编程技术网

Bash sh:…:在尝试使用plink调用shell脚本时不是标识符

Bash sh:…:在尝试使用plink调用shell脚本时不是标识符,bash,shell,unix,plink,Bash,Shell,Unix,Plink,下面是我的shell脚本,我正试图使用MachineB上的PLINK从MachineA(Windows机器)执行该脚本 我正在使用plink执行shell脚本,如下所示 C:\PLINK>plink uname@MachineB -m test.sh Using keyboard-interactive authentication. Password: Using keyboard-interactive authentication. Your Kerberos password wi

下面是我的shell脚本,我正试图使用
MachineB
上的
PLINK
MachineA
(Windows机器)执行该脚本

我正在使用
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.
这就是每当我试图像上面那样运行时,我总是遇到的错误

sh: HIVE_OPTS= -hiveconf mapred.job.queue.name=hdmi-technology: is not 
an identifier

我的shell脚本有问题吗?还是一些尾随空格?我想不出来。我正在从windows机器运行
PLINK
我认为
-m
选项用于从本地文件读取要在远程机器上执行的命令。如果我对行尾的评论不起作用,试试看

plink uname@MachineB test.sh
确保
test.sh
可通过运行

chmod +x test.sh

在MachineB上。

错误消息上的
sh:
前缀表示脚本是由
sh
执行的,而不是
bash

bash允许您将设置变量和将其导出到单个命令中结合起来:

export foo=bar
sh或至少一些旧版本的sh要求将这两个操作分开:

foo=bar ; export foo
不识别
export foo=bar
语法的sh版本将把字符串
foo=bar
解释为变量名(并且是非法的,因为它不是标识符)

安排由bash执行脚本,或者更改以下内容:

export HIVE_OPTS="$HIVE_OPTS -hiveconf mapred.job.queue.name=hdmi-technology"
为此:

HIVE_OPTS="$HIVE_OPTS -hiveconf mapred.job.queue.name=hdmi-technology"
export HIVE_OPTS
因此,由于您在脚本的一开始就引用了
$HIVE\u OPTS
,因此几乎可以肯定它已经导出了,因此您可以直接删除
导出

(您还需要避免任何其他特定于bash的特性。)


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

如果您在本地Windows计算机上创建了
test.sh
,则必须确保该文件具有Unix,不是Windows,它的行结尾可以在远程Unix主机上正常运行。谢谢chepner。如何确保
test.sh
具有unix文件结尾?我正在使用
Notepad++
创建test.sh文件,因为有一个选项可以以unix格式创建它,我也用同样的方法创建了test.Hm文件。在远程计算机上,您可以尝试
file test.sh
,并确保它没有说明任何关于CRLF行终止符的内容。我已从您的问题中删除了更新。如果您仍然想问这个问题,请发布一个新问题(请参阅此问题。谢谢Keith,它修复了我以前的问题,但我遇到了新错误,我已使用更新的shell脚本更新了我的问题。如果您能提供更多建议,那将非常好。您应该为此打开一个新问题,而不是继续在这里。
HIVE_OPTS="$HIVE_OPTS -hiveconf mapred.job.queue.name=hdmi-technology"
export HIVE_OPTS