Sponsored Content
Top Forums Shell Programming and Scripting pass function as argument to a function Post 302429212 by presul on Sunday 13th of June 2010 01:20:28 PM
Old 06-13-2010
pass function as argument to a function

I have the following code :
Code:
function1 ()
{
   print "January"
}

function2()
{
    case $1 in
                  January)
                  print "Dzisiaj mamy styczen"
                  ;;
                  *)                  
                  ;;

}

main()
{
      Month="`function2 $(function1)`"
      print "$Month"
}


# start of a program
main


Above code doesn't work.

Please help how to pass function1 as argument to function2 and save output in variable Month.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Passing Argument to Function

May i know how to pass an argument to a function in a shell script? Sorry, i din stated that it is in a shell script in my previous post. Means: checkStatus() { ........... } read status; I wanna use the status in the function checkstatus, how... (2 Replies)
Discussion started by: AkumaTay
2 Replies

2. UNIX for Dummies Questions & Answers

Pass argument to function

Hi, Can someone please explain to me how I can get a function to recognize a file given as an argument to a script. Suppose the script has the argument as follows: sh script file and the function is as follows: function display_file () { cat $1 } and it s then called #main program... (1 Reply)
Discussion started by: Knotty
1 Replies

3. Shell Programming and Scripting

How to pass variables to FUNCTION ?

Hi... Actually, I want to pass a few variables to the function and print it. But, its looks like not working. Could some body help me how could i do that ?... below is my program... #!/usr/bin/ksh usage() { echo "Usage: $0 -n -a -s -w -d" exit } rename() { echo "rename $1 $2"... (5 Replies)
Discussion started by: bh_hensem
5 Replies

4. Shell Programming and Scripting

Passing more than one argument in a function

Hi All, Calling a function with one argument and storing the return value in a shell script is as below:( so far I know) value="`fun_1 "argument1"`" Its working perfectly for me. Can u help me with passing more than one argument and storing the return value Thnaks in advance JS (1 Reply)
Discussion started by: jisha
1 Replies

5. Shell Programming and Scripting

pass parameter to function

HI all I have a code like ############################################## minyear() { curryear=$1 echo $curryear } ##Main Program ## minyear exit ####### when i execute "sh scriptname 2005" output should be like 2005 but the output is blank. I guess i need to pass parameter to... (3 Replies)
Discussion started by: vasuarjula
3 Replies

6. Shell Programming and Scripting

Function call with argument doubt

Hi all, I am having a problem with user defined function call. I am new into the concept of shell script UDFs. My function is: iterate_directory() { cd $1 k=0 for i in * do if then ARR=${i} fi done echo ${ARR } } (4 Replies)
Discussion started by: canishk
4 Replies

7. Shell Programming and Scripting

Passing commandline argument to a function

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 (2 Replies)
Discussion started by: siba.s.nayak
2 Replies

8. Shell Programming and Scripting

passing argument from one function to another

Hi all, In the given script code . I want to pass the maximum value that variable "i" will have in function DivideJobs () to variable $max of function SubmitCondorJob(). Any help? Thanks #!/bin/bash ... (55 Replies)
Discussion started by: nrjrasaxena
55 Replies

9. Shell Programming and Scripting

Strange third argument in shell function

In one of my shell function I found the following set_default_values () { prog=$1 PROC_DT=$2 RESET_ALL="${3-N}" #echo "Processing date as passed = , Program name = " ...... I understand the first and second arguments, but don't understand... (1 Reply)
Discussion started by: digioleg54
1 Replies

10. Shell Programming and Scripting

How to pass variable from one function to another function?

updateEnvironmentField() { linewithoutquotes=`echo $LINE | tr -d '"'` b() } I want to pass variable named $linewithoutquotes to another method called b(), which is called from updateEnvironmentField() method. How to do the above requirement with shell script (1 Reply)
Discussion started by: pottic
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 08:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy