0

I have a script which runs fine when executed in Bash shell (with Red Hat Linux), however this same script which fails on a Solaris 10 (DB) server where ksh is being used to execute this script. This script basically reads line by line from a file and executes a stored proc (in Oracle). Below is my script :

#/bin/sh

for i in $(cat subscriber.txt); do

        SUBSCRIBER_ID="'$i'"
        sqlplus -s myuser/myuser  <<EOF
        execute delete_learnings($SUBSCRIBER_ID);
        commit;
        EXIT    
EOF
done

The error I get is :

./removeLearnings.sh: syntax error at line 3: `$' unexpected

Any idea what might be going wrong? Should I change the script to have the ksh? I am not able to debug on this machine since it's a customer environment (which I don't have access to).

1
  • 5
    Solaris /bin/sh is not POSIX compliant and does not recognize the $(…) notation — unless, perhaps, you have Solaris 11. Note that you're not using ksh; the shebang says #!/bin/sh and not #!/bin/ksh. Commented Mar 11, 2016 at 7:09

3 Answers 3

6

The issue is the $(...) construction which is POSIX compliant but unsupported by the legacy Bourne shell which /bin/sh is on Solaris 10 and older.

You can either replace your shebang to call the Solaris POSIX compliant shell:

#!/usr/xpg4/bin/sh

or use this legacy syntax (less recommended):

for i in `cat subscriber.txt`; do
Sign up to request clarification or add additional context in comments.

2 Comments

Either one of these should work right ? Sorry I am asking basic questions , kinda of a noob in unix :)
Cool , I've asked them to change it. Once it works I will mark your answer as the correct one. Thanks !
0

you are trying to execute a sh( bourne shell) script on ksh (Korn shell). Try changing the shebang (#!/bin/bash) to (#!/bin/ksh)

Comments

0

Looping over text files with for is a bad idea, anyway. See http://mywiki.wooledge.org/BashFAQ/001- the recommended syntax is more portable, too:

while read stuff; do
    : things with "$stuff"
done <subscriber.txt

You would normally use read -r but I don't know if that's available on Solaris.

However, very often, a shell loop is altogether the wrong approach. A single SQL invocation is a lot better and more robust:

( sed 's/.*/execute delete_learnings(&);/'
  printf "commit;\nEXIT\n" ) |
sqlplus -s myuser/myuser

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.