Preventing wildcard expansion in "read"


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Preventing wildcard expansion in "read"
# 1  
Old 11-01-2005
Preventing wildcard expansion in "read"

Hi, I'm trying to use "read" to read in SQL lines and then apply to UDB. However KSH is expanding the *'s in the SQL into a list of all the files in the current directory...

Anyway to turn this off?

Code:
        while read SQLStatement
        do
                echo "Running : " $SQLStatement |tee -a $LogFile
                db2 $SQLStatement >> $LogFile

                if      [ $? -ne 0 ] ; then
                        echo "Error: Problem in running: " $SQLStatement
                        exit 1
                fi
        done < $InputSQLFile

I tried using

select \* from tablename
"select * from tablename"

in the inputfile with no success and also tried various options on "read" with no luck... anyone got any ideas?

Last edited by gaijin 06; 11-01-2005 at 06:33 AM..
# 2  
Old 11-01-2005
Try moving the quote in the echo statement:
echo "Running : $SQLStatement" |tee -a $LogFile

and quoting other uses like this:
db2 "$SQLStatement" >> $LogFile
# 3  
Old 11-01-2005
Data

Thanks for the suggestion.... I tried this, but the expansion of the * character happens during the read.... if I echo the string out straight after the read then it is already expanded.
# 4  
Old 11-01-2005
Read is fine for me...
Code:
$ cat somefile
SELECT * FROM tablename
$ echo $0
ksh
$ while read SQLStatement; do
>   echo "${SQLStatement}"
> done < somefile
SELECT * FROM tablename
$ uname -srm
SunOS 5.10 sun4u

Cheers
ZB
# 5  
Old 11-01-2005
Odd.... I tried your example ZB and it also worked for me! Smilie

However when I execute it in the script it is still expanding the * for me... I don't know why. I'll post the entire script in case it is something stupid...

Code:
#!/bin/ksh
#*******************************************************************
#* Date         : 01-Nov-2005
#* Purpose      : To clear up NV trade ref tables, used by STP application
#*******************************************************************

typeset Execdate
typeset -i ErrorFound=0
typeset SQLStatement
typeset InputSQLFile
typeset LogFile

#********************************************************
# Function  : Main
#********************************************************
Main()
{

        #Set up logfile, input file and date

        Execdate=$(date '+%Y%m%d%H%M%S')

        LogFile=/home/fox/foxt/scripts/nv_trade_daily_clearup.log.$Execdate
        echo Info:  NV Trade Daily Clearup Job Start at :$Execdate |tee -a $LogFile

        InputSQLFile=/home/fox/foxt/scripts/nv_trade_daily_clearup.sql
        echo "Info: InputSQLFile is " $InputSQLFile |tee -a $LogFile

        LogFile=/home/fox/foxt/scripts/nv_trade_daily_clearup.log.$Execdate
        echo "Info: LogFile is " $LogFile |tee -a $LogFile


        # Read in one line at a time, execute against DB2 and check for errors

        while read SQLStatement
        do
                echo "Running : " $SQLStatement |tee -a $LogFile
                db2 ${SQLStatement} >> $LogFile

                if      [ $? -ne 0 ] ; then
                        echo "Error: Problem encountered in running: " $SQLStatement
                        exit 1
                fi
        done < $InputSQLFile

        # Clean up logfiles older than 1 week

        echo Info:  NV Trade Daily Clearup Job End  |tee -a $LogFile
        find /home/fox/foxt/scripts -name "nv_trade_daily_clearup.log*" -mtime +7 -exec rm {} \;

        exit 0
}

Main $*

the input file

Code:
connect to OES
set current schema OES
select * from nv_trade


and the output I see

Code:
Info: NV Trade Daily Clearup Job Start at :20051102094620
Info: InputSQLFile is  /home/fox/foxt/scripts/nv_trade_daily_clearup.sql
Info: LogFile is  /home/fox/foxt/scripts/nv_trade_daily_clearup.log.20051102094620
Running :  connect to OES
Running :  set current schema OES
Running :  select FIX_release_groups_patch.sql chkDiskSpace.awk dbBack dbstart.csh fix_daily_clearup.sh fix_daily_clearu
p.sql fix_daily_clearup2.sh fix_daily_clearup2.sql fixgateway.csh fixgateway.csh.20040129 fixgateway_appia.csh foxstart.
csh foxstart.csh.20050201 foxstart.csh.20050420 mtbadvisory.csh nv_trade_daily_clearup.log.20051102094056 nv_trade_daily
_clearup.log.20051102094620 nv_trade_daily_clearup.sh nv_trade_daily_clearup.sql old_mtb.sh preEodRG.csh test from nv_tr
ade
Error: Problem encountered in running:  select FIX_release_groups_patch.sql chkDiskSpace.awk dbBack dbstart.csh fix_dail
y_clearup.sh fix_daily_clearup.sql fix_daily_clearup2.sh fix_daily_clearup2.sql fixgateway.csh fixgateway.csh.20040129 f
ixgateway_appia.csh foxstart.csh foxstart.csh.20050201 foxstart.csh.20050420 mtbadvisory.csh nv_trade_daily_clearup.log.
20051102094056 nv_trade_daily_clearup.log.20051102094620 nv_trade_daily_clearup.sh nv_trade_daily_clearup.sql old_mtb.sh
 preEodRG.csh test from nv_trade

# 6  
Old 11-01-2005
Quote as per Perderabo's recommendations then repost the code.

ZB
# 7  
Old 11-01-2005
Hmm, it seems to be working when I echo now, but not issuing to db2

Code:
        while read SQLStatement
        do
                echo "Running :  $SQLStatement" |tee -a $LogFile
                db2 "$SQLStatement" >> $LogFile

                if      [ $? -ne 0 ] ; then
                        echo "Error: Problem encountered in running: " $SQLStatement
                        exit 1
                fi
        done < $InputSQLFile


Last edited by zazzybob; 11-01-2005 at 09:25 PM.. Reason: fixed up code tag
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Failure: if grep "$Var" "$line" inside while read line loop

Hi everybody, I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o My code: #!/bin/sh set -e set -u export IFS= optl="Optl" LOCSTORCLI="/opt/lsi/storcli/storcli" ($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies

2. UNIX for Advanced & Expert Users

"GET" command retrieves multiple files while using wildcard

Hi All I am using GNU/Linux This is regarding the get command to retrieve files (filename with wild card characters) from remote server. I thought Get command can retrieve only 1 file irrespective of the files it has on the remote server And it is the function of mget to retrieve all... (7 Replies)
Discussion started by: sparks
7 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

Read from "list1" and list matches in "list2"

I want to print any matching IP addresse in List1 with List 2; List 1 List of IP addresses; 161.85.58.210 250.57.15.129 217.23.162.249 74.76.129.101 30.221.177.237 3.147.200.59 170.58.142.64 127.65.109.33 150.167.242.146 223.3.20.186 25.181.180.99 2.55.199.32 (3 Replies)
Discussion started by: lewk
3 Replies

5. Shell Programming and Scripting

Purpose of "read" and "$END$" in ksh ?

Hi, Could anyone please shed some light on the following script lines and what is it doing as it was written by an ex-administrator? cat $AMS/version|read a b verno d DBVer=$(/usr/bin/printf "%7s" $verno) I checked that the cat $AMS/version command returns following output: ... (10 Replies)
Discussion started by: dbadmin100
10 Replies

6. AIX

Preventing screen redraw when "more" exits

In previous releases of AIX (<5.3) the "more" command didn't redraw the screen upon exit. This helped when searching in a text document or man page because one could look for the relevant part of it, exit and use the left-over at the screen as reference for typing the next command. Alas, this... (2 Replies)
Discussion started by: bakunin
2 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. Shell Programming and Scripting

read -p "prompt text" foo say "read: bad option(s)" in Bourne-Shell

Hallo, i need a Prompting read in my script: read -p "Enter your command: " command But i always get this Error: -p: is not an identifier When I run these in c-shell i get this error /usr/bin/read: read: bad option(s) How can I use a Prompt in the read command? (9 Replies)
Discussion started by: wiseguy
9 Replies

9. Shell Programming and Scripting

preventing "break" in a script

Not sure if I am using the correct terminology: I have a user setup in a menu. I want to let the user browse a file using the pg. I want to prevent the person from doing <ctrl>c and being able to exit the script to the command line. How do I do this? (6 Replies)
Discussion started by: MizzGail
6 Replies

10. Shell Programming and Scripting

how to request a "read" or "delivered" receipt for mails

Dears, I've written a script which allows me to send mails in different formats with different attaches. Now I still want to add a feature to this script. My users would like to be able to receive a "read" or "delivered" receipt for their mails. The script send mails on behalve of an specific... (1 Reply)
Discussion started by: plelie2
1 Replies
Login or Register to Ask a Question