Quote:
Originally Posted by Abhishek Ghose
"." runs the script in current shell, as you said. The reason for doing this is we want B.sh to recognise the variable "var"(which can only be recognised in the shell that it was defined in)
If you are not planning to pass any variable, then rather use metohd 2. But a caveat: Method 2 implicitly assumes that your script understands certain variable names (like "var" in my examples). Basically , this means that you might not be able to re-use B.sh. Also, better check whether the variable in question is null first. In such a case, make B.sh throw out an error message and abort execution.
In which scenario did it hang? When the scripts were written according to method 1 or method 2?
A statement like X=`B.sh` might hang in scenario 1, as it expects a commandline input. But not sure.
My script code as follows
--------------------------------------------
. database_checking.sh
echo "Database Name" $db_name
echo "set feed off verify off pagesize 0
select username from user_users;"|sqlplus -s /@$db_name|read user_name
---------------------------------------------------------------
My database_checking.sh code follows which return db_name variable to above code....which is furthur used for retrieving username ...
-----------Start------------------------------------------------
db_var=1
while test $db_var -eq 1
do
echo "\n\t\t\tEnter Database Name"
echo "\t\t\t[ Example:marketbld.uk.d.ch ] or Press [ 'Q'/'q'] to exit :\c"
read db_name
func_meta_ch "$db_name"
if [ "!$db_name!" != "!!" -a $var_meta_ch -eq 0 ]
then
expr $db_name + 2 >/dev/null 2>&1
db_val=$?
if [ $db_val -ne 0 ]
then
echo "set feed off verify off pagesize 0
select count(1) from mktactivity;"|sqlplus -s /@$db_name|read sqldb_name
expr $sqldb_name + 2 >/dev/null 2>&1
db_cnt=$?
if [ "!$sqldb_name!" = "!ERROR:!" ]
then
echo "\t\t\tError: Database name entered does not exist."
else
if [ $db_cnt -ne 0 ]
then
echo "\t\t\tError: Database name entered does not exist."
else
db_var=2
fi
fi
else
echo "\t\t\tError: Database name entered does not exist."
fi
else
echo "\t\t\tError: Invalid Database name."
fi
done
echo $db_name
------------End ------------------