Results 1 to 4 of 4
Hi, all.
I am trying to write a ksh script that accepts an SQL query from the user like this:
Code:
script_name select * from schema.table;
When the script runs, ...
- 11-15-2008 #1Just Joined!
- Join Date
- Oct 2008
- Posts
- 11
turn off globbing within script
Hi, all.
I am trying to write a ksh script that accepts an SQL query from the user like this:
When the script runs, the user will be prompted for a password to the database and then the query will run and return results. The problem is, the wildcard is returning a list of all the filenames in my current directory. Therefore, I need to turn off globbing.Code:script_name select * from schema.table;
I have found advice on the internet but none that apply to me. First, I need to turn off globbing within my script so I cannot use "set -f". Also, I cannot expect the user to input the * as '*'. Is there a way to accept a query normally as I have above? Here's my code:
I have tried the following and none of them work:Code:if [ -n "$*" ]; then QUERY="$*" fi mysql -usystem -p$password -e "$QUERY"
'$QUERY' => $QUERY
'"$QUERY"' => "$QUERY"
"$QUERY" => glob
"'$QUERY'" => glob
$QUERY => glob
Thanks for your help.
- 11-15-2008 #2Just Joined!
- Join Date
- Oct 2008
- Posts
- 11
I made a mistake, actually. I meant to say that I cannot user "set -o noglob" since I'm doing this in ksh.
- 11-16-2008 #3Linux User
- Join Date
- Jun 2007
- Posts
- 318
The problem is the shell environment is expanding the * before running the script. So there's nothing you can do in the script to get that *. The only solution I see is have the script prompt the user for the SQL query instead having the user pass it as a paramter list.
- 11-16-2008 #4Just Joined!
- Join Date
- Oct 2008
- Posts
- 11
Thanks for your help. I might go with that or with forcing the user to put the query in single quotes after all.
Code:if [ -n "$*" ]; then QUERY="$*;" fi mysql -u user_name -p$password -e "$QUERY"
Code:script_name 'select * from schema.table'


Reply With Quote