I am using a shell script to read SQL statements stored in a DB2 table and write them out to a file. The problem I have is that some SQL statements have an "*" in them which gets resolved as the list of files in the current directory when I run the script. How can I prevent the "*" from being resolved??
Actual SQL: SELECT * FROM RTDS.TSPSTOPS
Result SQL: SELECT gen.out gen.sql gen2.sql getsql.sh getsql2.sh sqlrow.out sqltxt.out test.sh FROM RTDS.TSPSTOPS
No variable in here => no expansion will take place. Maybe your example is too short? Do you in reality have something like "x=$(db2 $var fetch from c1)"? In this case surround $var with quotes.
My apologies for my example not being very clear. The "Actual SQL" shown in my OP is the value that the fetch will return into the shell variable "sqlrow". Since the Actual SQL has an "*" in it, when I echo $sqlrow, the * gets resolved and substitutes in the list of files from the current directory.
So, duh, I was able to resolve that by putting double quotes around the variable on the echo like : echo "$sqlrow"
Now, the plot thickens a bit. The sql is stored in a varchar(32000) on the source table. When I put the double quotes on the echo, I now get a record echo'd out that is 32000 bytes long. (The actual SQL statements will range from 50 - 10000 bytes). So, I don't want to write out all that extra space on the end of each record.
I can get the length of the sql, and I'm now trying to substr it in awk as follows where $rowlen contains the length of the sql:
The sql is stored in a varchar(32000) on the source table. When I put the double quotes on the echo, I now get a record echo'd out that is 32000 bytes long.
If the column is defined as varchar(32000), I don't understand why you are retrieving what appears to be full width columns. I'm using Oracle instead of DB2, but the principle should be the same.
Here is my output:
Have you tried trimming the output as you select it from the DB2 database?
The output is the same (i.e., no trailing spaces for the data), unless the long line of dashes is giving you a problem:
It's been a while since I worked with DB2, but, the db2 command line verb may have a switch that would suppress the output of padded spaces, if it (i.e., the db2 command line verb) is the culprit. Do you get padded spaces when you run the query interactively? Say, from within Toad?
Hi All,
I am having a challange to pass the asterisk in the variable. Basically, I am writing a shell script to check if a marker file exists but when I am assigning the varialbe it cannot use the wildcard asterisk as expected, therefore, my program is always outputs "Marker file is not... (4 Replies)
I was trying to replace a string ( for eg - @@asterisk@@ to * ) in variable using
cat $INFILE | while read LINE
do
stmt1=`echo $LINE | sed 's/@@asterisk@@/\*/g'`
stmt=$stmt' '$stmt1
stmt2=`echo $LINE`
STATEMENT=$STATEMENT' '$stmt2
done
echo 'Statement with sed -- > '... (5 Replies)
I'm writing a script that will ssh to a number of hosts and run commands. I'm a bit stumped at the moment as some of the commands that I need to run contain wildcards (i.e. *), and so far I have not figured out how to escape the * character so the script doesn't expand it. More specifically, here's... (9 Replies)