Sponsored Content
Top Forums Shell Programming and Scripting Function - Make your function return an exit status Post 303037622 by meister29 on Thursday 8th of August 2019 06:41:09 AM
Old 08-08-2019
Function - Make your function return an exit status

Hi All,

Good Day, seeking for your assistance on how to not perform my 2nd, 3rd,4th etc.. function if my 1st function is in else condition.

Code:
#Body

function1() 
{
if [ - e test.xt] 
then
echo "exist" 
else
echo "not exist" 
} 

#if not exist in function1 my all other function will not proceed. 

function2() 
{
cat test.txt
} 

#Main
function1
function2
etc..

if i put my function1 and function2 in main it always proceed on function 2 even though theres an error in function1. im not sure how to start.

TIA
 

10 More Discussions You Might Find Interesting

1. HP-UX

Return of EXIT status ( $? )

I have the question: How return the exit code from then assign : VAR=$(command ) for ex. VAR=$(ls ....) VAREXIT=$? echo $VAREXIT VAREXIT is equal to 0 if the directory exist or not exist. WHI?? if i execute the command direct from line-command , the value of $? is different if... (1 Reply)
Discussion started by: ZINGARO
1 Replies

2. Shell Programming and Scripting

evaluate return status of a function

Hi all I'm trying to evalute the return status of a function without much success. I've put a very basic example below to explain. check_ok() works fine but when used within an if statement, it always returns true, whether it is true or false. I'm guessing it returns true as the function... (4 Replies)
Discussion started by: tig2810
4 Replies

3. Shell Programming and Scripting

command does not return exit status due to tee

Hi, I am using /bin/sh. I want to display the stdout and stderr on the terminal as well as save it in a file, so I'm using this command. gmake all 2>&1 | tee log But even if gmake fails, it's always giving 0 as exit status, i suppose because of tee. # false 2>&1 | tee Log # echo $? 0... (2 Replies)
Discussion started by: anand_bh
2 Replies

4. Shell Programming and Scripting

Return a value from called function to the calling function

I have two scripts. script1.sh looks -------------------------------- #!/bin/bash display() { echo "Welcome to Unix" } display ----------------------------- Script2.sh #!/bin/bash sh script1.sh //simply calling script1.sh ------------------------------ (1 Reply)
Discussion started by: mvictorvijayan
1 Replies

5. Shell Programming and Scripting

exit from function

Hi all, My kshell code is not working, when I use a function to return something. But when I use the same function as without returning any values, it is working. Pls help me here. Code1 : func1 () { y=`echo $x | grep XXX| cut -f 2 -d ' '` if ; then exit 100 ... (2 Replies)
Discussion started by: poova
2 Replies

6. Shell Programming and Scripting

Exit from function

Hi, I just want to exit from function if some condition doesnt meet then control should go back to main program and start running from where it left.. When i used "exit" inside the function, its simply exited from entire script and it didnt run anymore.. Any idea how to do this.. Thanks... (3 Replies)
Discussion started by: nram_krishna@ya
3 Replies

7. UNIX for Advanced & Expert Users

Cannot exit from a function?

Hi, Is there a way to exit from a subcommand, which is a function in my example below? #!/bin/ksh function exitFunction { if ]; then echo "success" elif ]; then echo "failed" exit 1 # the exit problem fi exit 0 } ... (2 Replies)
Discussion started by: chstr_14
2 Replies

8. Shell Programming and Scripting

After exit from function it should not call other function

Below is my script that is function properly per my conditions but I am facing one problem here that is when one function fails then Iy should not check other functions but it calls the other function too So anyone can help me how could i achieve this? iNOUT i AM GIVING TO THE... (1 Reply)
Discussion started by: rohit22hamirpur
1 Replies

9. Shell Programming and Scripting

Clear contents of specified directories, then return exit status

Hello, this is my first post here. I'm attempting to write a bash shell script to rm the contents of a directory without deleting the directory, specifically in OS X 10.10 . Here's what I have: function clear() { USER="$USER" DIR=$1 rm -rfv /Users/"$USER"/library/$DIR/* } clear... (6 Replies)
Discussion started by: YouNicks
6 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
Glib::Object::Introspection(3pm)			User Contributed Perl Documentation			  Glib::Object::Introspection(3pm)

NAME
Glib::Object::Introspection - Dynamically create Perl language bindings SYNOPSIS
use Glib::Object::Introspection; Glib::Object::Introspection->setup( basename => 'Gtk', version => '3.0', package => 'Gtk3'); # now GtkWindow, to mention just one example, is available as # Gtk3::Window, and you can call gtk_window_new as Gtk3::Window->new ABSTRACT
Glib::Object::Introspection uses the gobject-introspection and libffi projects to dynamically create Perl bindings for a wide variety of libraries. Examples include gtk+, webkit, libsoup and many more. DESCRIPTION
"Glib::Object::Introspection->setup" To allow Glib::Object::Introspection to create bindings for a library, it must have installed a typelib file, for example "$prefix/lib/girepository-1.0/Gtk-3.0.typelib". In your code you then simply call "Glib::Object::Introspection->setup" to set everything up. This method takes a couple of key-value pairs as arguments. These three are mandatory: basename => $basename The basename of the library that should be wrapped. If your typelib is called "Gtk-3.0.typelib", then the basename is 'Gtk'. version => $version The particular version of the library that should be wrapped, in string form. For "Gtk-3.0.typelib", it is '3.0'. package => $package The name of the Perl package where every class and method of the library should be rooted. If a library with basename 'Gtk' contains an object 'GtkWindow', and you pick as the package 'Gtk3', then that object will be available as 'Gtk3::Window'. The rest are optional: search_path => $search_path A path that should be used when looking for typelibs. If you use typelibs from system directories, or if your environment is set up correctly, then this should not be necessary. name_corrections => { auto_name => new_name, ... } A hash ref that is used to rename functions and methods. Use this if you don't like the automatically generated mapping for a function or method. For example, if "g_file_hash" is automatically represented as "Glib::IO::file_hash" but you want "Glib::IO::File::hash" then pass name_corrections => { 'Glib::IO::file_hash' => 'Glib::IO::File::hash' } class_static_methods => [ function1, ... ] An array ref of function names that you want to be treated as class-static methods. That is, if you want be able to call "Gtk3::Window::list_toplevels" as "Gtk3::Window->list_toplevels", then pass class_static_methods => [ 'Gtk3::Window::list_toplevels' ] The function names refer to those after name corrections. flatten_array_ref_return_for => [ function1, ... ] An array ref of function names that return an array ref that you want to be flattened so that they return plain lists. For example flatten_array_ref_return_for => [ 'Gtk3::Window::list_toplevels' ] The function names refer to those after name corrections. Functions occuring in "flatten_array_ref_return_for" may also occur in "class_static_methods". handle_sentinel_boolean_for => [ function1, ... ] An array ref of function names that return multiple values, the first of which is to be interpreted as indicating whether the rest of the returned values are valid. This frequently occurs with functions that have out arguments; the boolean then indicates whether the out arguments have been written. With "handle_sentinel_boolean_for", the first return value is taken to be the sentinel boolean. If it is true, the rest of the original return values will be returned, and otherwise an empty list will be returned. handle_sentinel_boolean_for => [ 'Gtk3::TreeSelection::get_selected' ] The function names refer to those after name corrections. Functions occuring in "handle_sentinel_boolean_for" may also occur in "class_static_methods". "Glib::Object::Introspection->invoke" To invoke specific functions manually, you can use the low-level "Glib::Object::Introspection->invoke". Glib::Object::Introspection->invoke( $basename, $namespace, $function, @args) o $basename is the basename of a library, like 'Gtk'. o $namespace refers to a namespace inside that library, like 'Window'. Use undef here if you want to call a library-global function. o $function is the name of the function you want to invoke. It can also refer to the name of a constant. o @args are the arguments that should be passed to the function. For a method, this should include the invocant. For a constructor, this should include the package name. "Glib::Object::Introspection->invoke" returns whatever the function being invoked returns. Overrides To override the behavior of a specific function or method, create an appropriately named sub in the correct package and have it call "Glib::Object::Introspection->invoke". Say you want to override "Gtk3::Window::list_toplevels", then do this: sub Gtk3::Window::list_toplevels { # ...do something... my $ref = Glib::Object::Introspection->invoke ( 'Gtk', 'Window', 'list_toplevels', @_); # ...do something... return wantarray ? @$ref : $ref->[$#$ref]; } The sub's name and package must be those after name corrections. Converting a Perl variable to a GValue If you need to marshal into a GValue, then Glib::Object::Introspection cannot do this automatically because the type information is missing. If you do have this information in your module, however, you can use Glib::Object::Introspection::GValueWrapper to do the conversion. In the wrapper for a function that expects a GValue, do this: ... my $type = ...; # somehow get the package name that # corresponds to the correct GType my $real_value = Glib::Object::Introspection::GValueWrapper->new ($type, $value); # now use Glib::Object::Introspection->invoke and # substitute $real_value where you'd use $value ... SEE ALSO
gobject-introspection: <http://live.gnome.org/GObjectIntrospection> libffi: <http://sourceware.org/libffi/> AUTHORS
Emmanuele Bassi <ebassi at linux intel com> muppet <scott asofyet org> Torsten Schoenfeld <kaffeetisch at gmx de> LICENSE
This library is free software; you can redistribute it and/or modify it under the terms of the Lesser General Public License (LGPL). For more information, see http://www.fsf.org/licenses/lgpl.txt perl v5.14.2 2012-05-21 Glib::Object::Introspection(3pm)
All times are GMT -4. The time now is 12:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy