Shell script giving errors in ksh

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 :


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

        sqlplus -s myuser/myuser  <<EOF
        execute delete_learnings($SUBSCRIBER_ID);

The error I get is :

./ 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).


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:


or use this legacy syntax (less recommended):

for i in `cat subscriber.txt`; do

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

Looping over text files with for is a bad idea, anyway. See 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

Need Your Help

How to change the header background color of a QTableView

c++ qt qtableview qabstracttablemodel

The following is what I've currently tried. The header text changes color correctly but the background will not change from the default.

Iphone Deployment Target with ASIHTTPRequest

iphone objective-c asihttprequest

I'm having an issue trying to use ASIHTTPRequest libraries in my iPhone application.