Below is my shell script that I am trying to execute using PLINK on MachineB from MachineA(Windows Machine).
#!/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,
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
The
sh:prefix on the error message indicates that the script is being executed bysh, notbash.bash lets you combine setting a variable and exporting it into a single command:
sh, or at least some older versions of it, require these two actions to be separated:
A version of sh that doesn’t recognize the
export foo=barsyntax will interpret the stringfoo=baras a variable name (and an illegal one, since it isn’t an identifier).Either arrange for the script to be executed by bash, or change this:
to this:
For that matter, since you’re referring to
$HIVE_OPTSat the very beginning of your script, it’s almost certainly already exported, so you could just drop theexport.(You’ll also need to avoid any other bash-specific features.)
So why is the system invoking the shell with sh? The
#!/bin/bashsyntax is 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 could configure your system, using Folder Options, to invoke*.shfiles using bash, but that might introduce other problems.)