Question

Background: I need to port a ksh script from SunOS 5.10 to RHEL 5.8. It makes a call to isql to retrieve some data and, quite contrary to the intended application of final endpoint client utilities such as isql, it parses its out to be used by a variable in the shell script. Please note that I just inherited this and by no means did design such a hack myself. I certainly never would be parsing isql out to assign value to a var in shell -- if the script needed that info, I would use Perl with some API like DBD::DBI that is designed to marshall data between the application and the data store. But I have what I have and must work within the parameters.

What is happening is that the following piped input does return data on SunOS but not in RHEL:

echo "SELECT some_field FROM some_table WHERE some_crtra = 'X' \ngo" | isql -U$USER -P$PASS -D$DB -S$SERVER

That output on Solaris being:

 some_field 
 ------
 Y

(1 row affected)

From that point, the script uses awk to extract just the field value from the above stream but let's ignore that because that's not the problem.

Also please note that I am able to get the data executing the piped commands separately, i.e. by going manually into isql and running the SQL. So the SQL or the connection string are not the problem -- it is either how the piping streams data OR isql itself works differently on the different platforms.

Can anybody see why there is disparate response to the same input on the two systems? Any idea how I can change the piping to make it work?

Thanks

Was it helpful?

Solution

echo "SELECT some_field FROM some_table WHERE some_crtra = 'X' \ngo"

is non portable.

I would suggest instead:

printf "SELECT some_field FROM some_table WHERE some_crtra = 'X' \ngo\n"

From the ksh93 manual page:

When the first arg does not begin with a -, and none of the arguments contain a \, then echo prints each of its arguments separated by a space and terminated by a new-line. Otherwise, the behavior of echo is system dependent and print or printf described below should be used. See echo(1) for usage and description.

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