Sponsored Content
Top Forums Shell Programming and Scripting Passing Values from a shell script Post 302070639 by dhananjaysk on Thursday 6th of April 2006 09:33:54 AM
Old 04-06-2006
Please see the example

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 ------------------
 

10 More Discussions You Might Find Interesting

1. Programming

Passing Parameters and getting values back from a c program to Shell script

I am having a shell script which has to be called from a C program. I have to pass two parameters to this script. HOw can I do that? eg: int main() { char st1; char str2; // call a shell script call_sh(str1,str2) where call_sh is the name of the shell script. then i need to get the return... (5 Replies)
Discussion started by: Rajeshsu
5 Replies

2. Shell Programming and Scripting

passing values from sql to shell script

Hi guyz, Posting a thread after a long time. I want to pass two variables to unix shell script from sql script. Note: I am calling sql script from unix script. sql script has 2 variables one is the return code for status of program run and second one email flag. I don't know how to capture... (3 Replies)
Discussion started by: sachin.gangadha
3 Replies

3. Shell Programming and Scripting

Passing the values to the secondary script when it invoked by primary script

Hi, When I invoke a script s1.sh it will call an another script s2.sh by itself. This script s2.sh will call some java files, so while running the script it asks for a file name to be processed. Which we can see in the screen. The file name to be processed is present in script s1.sh Now... (1 Reply)
Discussion started by: venu_eie
1 Replies

4. UNIX for Advanced & Expert Users

Passing the values to the secondary script when it invoked by primary script

Hi, When I invoke a script s1.sh it will call an another script s2.sh by itself. This script s2.sh will call some java files, so while running the script it asks for a file name to be processed. Which we can see in the screen. The file name to be processed is present in script s1.sh Now I... (2 Replies)
Discussion started by: venu_eie
2 Replies

5. Shell Programming and Scripting

Handling values with space while passing commandline argument from wrapper script in KSH

Hi there, I have a wapper script which passes the argument from command prompt to inner script.. It works fine as long as the argument containing single word. But when value contains multiple word with space, not working as expected. I tried my best, couldn't find the reason. Gurus, pls.... (2 Replies)
Discussion started by: kans
2 Replies

6. Shell Programming and Scripting

passing values to the shell script

Hi, Solaris : 10 . I have 3 database in single file system i.e. /d01 . whenever I connect to oracle user using the below method #su - oracle It will prompt for which database environment you want to set(PROD,TEST,UAT) : whichever i need i will enter required DATABASE and perform my... (2 Replies)
Discussion started by: maooah
2 Replies

7. Shell Programming and Scripting

Passing PERL var values to SH Shell Script

Greetings all, If I have a SH script that calls a PERL script in the following way: perl $HOME/scripts/config.properties And in the config.properties PERL file, this Perl script only sets a number of environmental parameters in the following way: #!/usr/bin/perl $VAR1 = ( ... (3 Replies)
Discussion started by: gikyo12
3 Replies

8. Shell Programming and Scripting

Passing values from awk to shell variable

I am writing a script where I need awk to test if two columns are the same and shell to do something if they are or are not. Here is the code I'm working with: @ test = 0 ... test = `awk '{if($1!=$2) print 1; else print 0}' time_test.tmp` #time_test.tmp holds two values separated by a space... (3 Replies)
Discussion started by: Malavin
3 Replies

9. Shell Programming and Scripting

Query the table and return values to shell script and search result values from another files.

Hi, I need a shell script, which would search the result values from another files. 1)execute " select column1 from table_name" query on the table. 2)Based on the result, need to be grep from .wft files. could please explain about this.Below is the way i am using. #!/bin/sh... (4 Replies)
Discussion started by: Rami Reddy
4 Replies

10. Shell Programming and Scripting

Passing values to an XML file from shell script

:wall: Hi, I have an XML file with 5 tags. I need to pass values to the XML file from a shell script that will replace values in 2 of the tags. I cannot hardcode the tag values in XML and use replace command in script as the values are likely to change. Please help !!!!!!!!!!! (2 Replies)
Discussion started by: Monalisaa
2 Replies
escape(1)                                                       Mail Avenger 0.8.3                                                       escape(1)

NAME
escape - escape shell special characters in a string SYNOPSIS
escape string DESCRIPTION
escape prepends a "" character to all shell special characters in string, making it safe to compose a shell command with the result. EXAMPLES
The following is a contrived example showing how one can unintentionally end up executing the contents of a string: $ var='; echo gotcha!' $ eval echo hi $var hi gotcha! $ Using escape, one can avoid executing the contents of $var: $ eval echo hi `escape "$var"` hi ; echo gotcha! $ A less contrived example is passing arguments to Mail Avenger bodytest commands containing possibly unsafe environment variables. For example, you might write a hypothetical reject_bcc script to reject mail not explicitly addressed to the recipient: #!/bin/sh formail -x to -x cc -x resent-to -x resent-cc | fgrep "$1" > /dev/null && exit 0 echo "<$1>.. address does not accept blind carbon copies" exit 100 To invoke this script, passing it the recipient address as an argument, you would need to put the following in your Mail Avenger rcpt script: bodytest reject_bcc `escape "$RECIPIENT"` SEE ALSO
avenger(1), The Mail Avenger home page: <http://www.mailavenger.org/>. BUGS
escape is designed for the Bourne shell, which is what Mail Avenger scripts use. escape might or might not work with other shells. AUTHOR
David Mazieres Mail Avenger 0.8.3 2012-04-05 escape(1)
All times are GMT -4. The time now is 01:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy