Sponsored Content
Full Discussion: Return vs. Echo
Top Forums Shell Programming and Scripting Return vs. Echo Post 302283903 by gagan8877 on Wednesday 4th of February 2009 10:01:54 AM
Old 02-04-2009
Return vs. Echo

Hi cfajohnson

Thanks for the reply. In the code below GetData() calls get_primary and is_primary functions

GetData()
{

prim_mach=`get_primary`
gprim_mach=`is_primary`

echo $prim_mach
echo $gprim_mach
}

-------------------

is_primary()
{
TFILE=$TEMPDIR/tempFile.$$
this_server=`uname -n`
dbaccess << PRIM > /dev/null 2>&1
database sscDB;
unload to $TFILE select s_status from serverstbl where s_name = "$this_server";
PRIM
[ -f $TFILE ] &&
{
status=`cat $TFILE | awk -F"|" '{ print $1 }'`
rm $TFILE
[ "$status" = "P" ] && return 0
}
return 1
}

----------------

TFILE=$TEMPDIR/tempFile.$$
dbaccess << GPRIMM > /dev/null 2>&1
database sscDB;
unload to $TFILE select s_name from serverstbl where s_status = "P";
GPRIMM
[ -f $TFILE ] &&
{
status=`cat $TFILE | awk -F"|" '{ print $1 }'`
rm $TFILE
echo $status
}
return 0
}

----------------------------------------------------
echo $prim_mach prints the column value - echo is the only command I see in the code that can send the output to $prim_mach variable in GetData(). So echo sent value to $prim_mach. But it returned 0 too. How do I see the 0? I thought the variable $prim_mach will have 0 in it, but it showed the echoed value.


echo $gprim_mach prints nothing, becasue there is no echo. But it did return 0 or 1 depending upon the condition. How can I see that?

Thanks.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's

Hi All, Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'. I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
Discussion started by: manas6
0 Replies

2. UNIX for Advanced & Expert Users

Return the last echo in remsh !!!!

Hi, I have a question: the script A run in the HostA call the script B on the HostB: ex.. ksh:B ....... ........ ........ remsh HostB ec........ ...... ...... the prog.B on the host B make more function but the last command is echo of srting : ex ksk script B .... ...... (0 Replies)
Discussion started by: ZINGARO
0 Replies

3. Shell Programming and Scripting

echo 2 txt files to screen no carraige return

I have two text files, each of then only containing ONE line and NO carraige return or white space at the end...how do I echo both of these text files to the screen without putting an extra line? I want to do this from the command line. file1.txt: this is file1.txt 1 file2.txt: this is... (4 Replies)
Discussion started by: ajp7701
4 Replies

4. Shell Programming and Scripting

Difference between using "echo" builtin and /bin/echo

So in my shell i execute: { while true; do echo string; sleep 1; done } | read line This waits one second and returns. But { while true; do /bin/echo string; sleep 1; done } | read line continues to run, and doesn't stop until i kill it explicitly. I have tried this in bash as well as zsh,... (2 Replies)
Discussion started by: ulidtko
2 Replies

5. UNIX for Dummies Questions & Answers

How to correctly use an echo inside an echo?

Bit of a weird one i suppose, i want to use an echo inside an echo... For example... i have a script that i want to use to take users input and create another script. Inside this script it creates it also needs to use echos... echo "echo "hello"" >$file echo "echo "goodbye"" >$file ... (3 Replies)
Discussion started by: mokachoka
3 Replies

6. Shell Programming and Scripting

With that logic this echoes "echo". Question about echo!

echo `echo ` doesn't echoes anything. And it's logic. But echo `echo `echo ` ` does echoes "echo". What's the logic of it? the `echo `echo ` inside of the whole (first) echo, echoes nothing, so the first echo have to echo nothing but echoes "echo" (too much echoing :P):o (2 Replies)
Discussion started by: hakermania
2 Replies

7. AIX

Return code 1 when echo to pipe

Hello, Our AIX box has recently been upgraded to TL12 (oslevel -s = 5300-12-04-1119). Now one of our ksh scripts is returning 1 when writing to a pipe, the command to write to the pipe is: echo "A" "B" "C" >> /usr/Pipe.Pipe Anyone have any ideas? Thanks (2 Replies)
Discussion started by: dendright
2 Replies

8. Shell Programming and Scripting

tcsh - understanding difference between "echo string" and "echo string > /dev/stdout"

I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here. I have following script (called out_to_streams.csh): #!/bin/tcsh -f echo Redirected to STDOUT > /dev/stdout echo Redirected to... (2 Replies)
Discussion started by: marcink
2 Replies

9. Shell Programming and Scripting

If echo statement return false

I have this code that sometimes return a false value and the code inside the if statement gets executed and error out. Any idea why? thanks. So I set a debug and see what the value for $ScriptElapsedTime Here is the value I got ScriptElapsedTime='03:20'. Base on this value the if... (10 Replies)
Discussion started by: nugent
10 Replies

10. Shell Programming and Scripting

Return: can only `return' from a function or sourced script

Not sure where the problem is. I can run the script without any issue using the following command. . /opt/app/scripts/cdc_migration.sh But it fails with the below error when I try it this way /opt/app/scripts/cdc_migration.sh /opt/app/scripts/cdc_migration.sh: line 65: return: can only... (1 Reply)
Discussion started by: svajhala
1 Replies
erl_eval(3erl)						     Erlang Module Definition						    erl_eval(3erl)

NAME
erl_eval - The Erlang Meta Interpreter DESCRIPTION
This module provides an interpreter for Erlang expressions. The expressions are in the abstract syntax as returned by erl_parse , the Erlang parser, or a call to io:parse_erl_exprs/2 . EXPORTS
exprs(Expressions, Bindings) -> {value, Value, NewBindings} exprs(Expressions, Bindings, LocalFunctionHandler) -> {value, Value, NewBindings} exprs(Expressions, Bindings, LocalFunctionHandler, NonlocalFunctionHandler) -> {value, Value, NewBindings} Types Expressions = as returned by erl_parse or io:parse_erl_exprs/2 Bindings = as returned by bindings/1 LocalFunctionHandler = {value, Func} | {eval, Func} | none NonlocalFunctionHandler = {value, Func} | none Evaluates Expressions with the set of bindings Bindings , where Expressions is a sequence of expressions (in abstract syntax) of a type which may be returned by io:parse_erl_exprs/2 . See below for an explanation of how and when to use the arguments LocalFunc- tionHandler and NonlocalFunctionHandler . Returns {value, Value, NewBindings} expr(Expression, Bindings) -> { value, Value, NewBindings } expr(Expression, Bindings, LocalFunctionHandler) -> { value, Value, NewBindings } expr(Expression, Bindings, LocalFunctionHandler, NonlocalFunctionHandler) -> { value, Value, NewBindings } expr(Expression, Bindings, LocalFunctionHandler, NonlocalFunctionHandler, ReturnFormat) -> { value, Value, NewBindings } | Value Types Expression = as returned by io:parse_erl_form/2, for example Bindings = as returned by bindings/1 LocalFunctionHandler = {value, Func} | {eval, Func} | none NonlocalFunctionHandler = {value, Func} | none ReturnFormat = value | none Evaluates Expression with the set of bindings Bindings . Expression is an expression (in abstract syntax) of a type which may be returned by io:parse_erl_form/2 . See below for an explanation of how and when to use the arguments LocalFunctionHandler and Nonlo- calFunctionHandler . Returns {value, Value, NewBindings} by default. But if the ReturnFormat is value only the Value is returned. expr_list(ExpressionList, Bindings) -> {ValueList, NewBindings} expr_list(ExpressionList, Bindings, LocalFunctionHandler) -> {ValueList, NewBindings} expr_list(ExpressionList, Bindings, LocalFunctionHandler, NonlocalFunctionHandler) -> {ValueList, NewBindings} Evaluates a list of expressions in parallel, using the same initial bindings for each expression. Attempts are made to merge the bindings returned from each evaluation. This function is useful in the LocalFunctionHandler . See below. Returns {ValueList, NewBindings} . new_bindings() -> BindingStruct Returns an empty binding structure. bindings(BindingStruct) -> Bindings Returns the list of bindings contained in the binding structure. binding(Name, BindingStruct) -> Binding Returns the binding of Name in BindingStruct . add_binding(Name, Value, Bindings) -> BindingStruct Adds the binding Name = Value to Bindings . Returns an updated binding structure. del_binding(Name, Bindings) -> BindingStruct Removes the binding of Name in Bindings . Returns an updated binding structure. LOCAL FUNCTION HANDLER
During evaluation of a function, no calls can be made to local functions. An undefined function error would be generated. However, the optional argument LocalFunctionHandler may be used to define a function which is called when there is a call to a local function. The argu- ment can have the following formats: {value,Func} : This defines a local function handler which is called with: Func(Name, Arguments) Name is the name of the local function (an atom) and Arguments is a list of the evaluated arguments. The function handler returns the value of the local function. In this case, it is not possible to access the current bindings. To signal an error, the function handler just calls exit/1 with a suitable exit value. {eval,Func} : This defines a local function handler which is called with: Func(Name, Arguments, Bindings) Name is the name of the local function (an atom), Arguments is a list of the unevaluated arguments, and Bindings are the current vari- able bindings. The function handler returns: {value,Value,NewBindings} Value is the value of the local function and NewBindings are the updated variable bindings. In this case, the function handler must itself evaluate all the function arguments and manage the bindings. To signal an error, the function handler just calls exit/1 with a suitable exit value. none : There is no local function handler. NON-LOCAL FUNCTION HANDLER The optional argument NonlocalFunctionHandler may be used to define a function which is called in the following cases: a functional object (fun) is called; a built-in function is called; a function is called using the M:F syntax, where M and F are atoms or expressions; an oper- ator Op/A is called (this is handled as a call to the function erlang:Op/A ). Exceptions are calls to erlang:apply/2,3 ; neither of the function handlers will be called for such calls. The argument can have the following formats: {value,Func} : This defines an nonlocal function handler which is called with: Func(FuncSpec, Arguments) FuncSpec is the name of the function on the form {Module,Function} or a fun, and Arguments is a list of the evaluated arguments. The function handler returns the value of the function. To signal an error, the function handler just calls exit/1 with a suitable exit value. none : There is no nonlocal function handler. Note: For calls such as erlang:apply(Fun, Args) or erlang:apply(Module, Function, Args) the call of the non-local function handler corresponding to the call to erlang:apply/2,3 itself-- Func({erlang, apply}, [Fun, Args]) or Func({erlang, apply}, [Module, Function, Args]) --will never take place. The non-local function handler will however be called with the evaluated arguments of the call to erlang:apply/2,3 : Func(Fun, Args) or Func({Module, Function}, Args) (assuming that {Module, Function} is not {erlang, apply} ). Calls to functions defined by evaluating fun expressions "fun ... end" are also hidden from non-local function handlers. The nonlocal function handler argument is probably not used as frequently as the local function handler argument. A possible use is to call exit/1 on calls to functions that for some reason are not allowed to be called. BUGS
The evaluator is not complete. receive cannot be handled properly. Any undocumented functions in erl_eval should not be used. Ericsson AB stdlib 1.17.3 erl_eval(3erl)
All times are GMT -4. The time now is 06:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy