Question

I have executed the below code in one linux machine, there its executing fine, but when i execute in another linux machine, its giving errors like

 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

Please help me

Was it helpful?

Solution

The problem is that sh is usually softlinked to a specific shell. It can change even when the context change. In Ubuntu, sh is bash when you start an interactive shell and dash if you start a script. When I have switched from 10.04 to 12.04 all my sh shebanged scripts failed ! You might have a version problem as user2864740 pointed out in a comment.

One solution is to use a specific shell in the shebang like /bin/bash explicitly. Another is to make your scripts work for all the shell versions/flavors you may encounter ^^

OTHER TIPS

Your script uses all sorts of bash specific features, and trying to run it with /bin/sh is asking for trouble, since /bin/sh may not alias /bin/bash. Change the shebang line to #!/bin/bash, and I bet you're fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top