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
Linux Shebang的脚本在机器对机器中表现奇怪_Linux_Shell_Shebang - Fatal编程技术网

Linux Shebang的脚本在机器对机器中表现奇怪

Linux Shebang的脚本在机器对机器中表现奇怪,linux,shell,shebang,Linux,Shell,Shebang,我已经在一台linux机器上执行了下面的代码,执行得很好,但是当我在另一台linux机器上执行时,会出现如下错误 Error:( declaration is not correct -- at line array=($@) declare is not correct -- at line declare hash code: #! /bin/sh STR="SSIDRADIO0=RUSSIA&SSIDRADIO1=JAPAN&COUNTRY=TH

我已经在一台linux机器上执行了下面的代码,执行得很好,但是当我在另一台linux机器上执行时,会出现如下错误

 Error:( declaration is not correct -- at line array=($@)
        declare is not correct -- at line declare  hash


code:
#! /bin/sh
  STR="SSIDRADIO0=RUSSIA&SSIDRADIO1=JAPAN&COUNTRY=TH&RADIOB=1&RADIOA=0&TXPOWERRADIO0=8&TXPOWERRADIO1=12&RADIOBCHAN=3&RADIOACHAN=60&PUBLISHSSIDRADIO0=1&PUBLISHSSIDRADIO1=1&SUPPORTEDTXRATERADIO0=12&SUPPORTEDTXRATERADIO1=18&REFRESHRATE=2000&INACTPERIOD=600"
IFS='&'
set -- $STR
array=($@)
declare  hash
for i in "${array[@]}"; do IFS="=" ; set -- $i; hash[$1]=$2; echo ${hash[$1]} >>help;done
请帮助我

问题是sh通常软链接到特定的shell。即使上下文发生变化,它也可能发生变化。在Ubuntu中,启动交互式shell时sh是bash,启动脚本时是dash。当我从10.04切换到12.04时,我所有的sh shebanged脚本都失败了!用户2864740在评论中指出,您可能存在版本问题

一种解决方案是显式地在shebang-like/bin/bash中使用特定的shell。另一种方法是使脚本适用于您可能遇到的所有shell版本/风格。问题是sh通常软链接到特定的shell。即使上下文发生变化,它也可能发生变化。在Ubuntu中,启动交互式shell时sh是bash,启动脚本时是dash。当我从10.04切换到12.04时,我所有的sh shebanged脚本都失败了!用户2864740在评论中指出,您可能存在版本问题


一种解决方案是显式地在shebang-like/bin/bash中使用特定的shell。另一种方法是使脚本适用于您可能遇到的所有shell版本/风格^ ^

您的脚本使用了各种bash特定的功能,并且尝试使用/bin/sh运行它会带来麻烦,因为/bin/sh可能不是别名/bin/bash。将shebang行更改为/bin/bash,我敢打赌你很好。

你的脚本使用了各种bash特有的功能,试图用/bin/sh运行它是自找麻烦的,因为/bin/sh可能不是别名/bin/bash。将shebang行更改为/bin/bash,我打赌你很好。

系统可能有不同的sh外壳,例如一个可能有bash,另一个可能有ash。看看它到底是什么/bin/sh-版本可能会有所帮助。系统可能有不同的sh shell,例如一个可能有bash,另一个可能有ash。看看它到底是什么/bin/sh-版本可能会有所帮助。