Hi,
I have 2 ksh scripts.
Script1.ksh contains function definition.
script1.ksh
function f1() {
while getopts a:c: args
do
case $args in
a) ARG1=$OPTARG ;;
c) ARG2=$OPTARG ;;
\?) echo "Error no valid Arguments passed"
esac
done
echo $ARG1
echo $ARG2
script2.sh
. script1.ksh
sql_query="select * from emp"
f1 -a "ABCD1234" -c $sql_query
When I execute the script2.ksh, I am getting output as ABCD1234 and select
Where I should get the select * from emp.
Can any one please let me know where is the error?
Thanks,
Siba
Just use the follows.
f1 -a "ABCD1234" -c "$sql_query"
Here the variable $sql_query is having the string containing the space.
So you should use double quotes like "$sql_query".
Then only it will preserve the white space.
Now I ran the script and got the output as follows
ABCD1234
select func.sh sc.sh from emp
Cheers!!!
Turn off wildcard expansion before you call script1.ksh and use double quotes and you should be fine.
script2.ksh
#!/usr/bin/ksh
#
# disable filename substitution.
#
set -o noglob
. script1.ksh
sql_query="select * from emp"
f1 -a "ABCD1234" -c "$sql_query"
#
# enable filename substitution.
#
set +o noglob
sql_query="select * from emp"
f1 -a "ABCD1234" -c "$sql_query"
test:
$ ./script2.ksh
ABCD1234
select * from emp
ABCD1234
select script1.ksh script2.ksh from emp
Good luck.