How to execute functions or initiate functions as command line parameters for below requirement?
I have 7 functions those need to be executed as command line inputs, I tried with below code it’s not executing function. If I run the ./script 2 then fun2 should execute , how to initiate that function I tried case and if else also, how to initiate function from command line
Code:
if [ "$VAL" == "1" ]
then
fun1
elif [ "$VAL" == "2" ]
then
fun2
elif [ "$VAL" == "3" ]
then
fun3
elif [ "$VAL" == "4"]
then
fun4
elif [ "$VAL" ==" 5" ]
then
fun5
elif [ "$VAL" == "6" ]
then
fun6
elif [ "$VAL" == "7" ] then
fun7
else
echo -e "Invalid input.............\n"
Help
exit
fi
OR
Code:
case "$VAL" in
"1")
fun1
;;
"2")
fun2
;;
"3")
fun3
;;
*)
echo -e "Invalid input.............\n"
;;
esac
Last edited by Scrutinizer; 01-28-2013 at 09:48 AM..
Reason: code tags
All,
I have a sh script of the following tune:
function a () { #functionality.. }
function b () { #functionnlity.. }
function check () { # this function checks for env and if all fine call build }
function usage () { #sh usage details }
function build () { #calls either a or b or... (5 Replies)
hi
could anybody please suggest me how to put a function memory for particular user.
say i am a user rao. want have a function foo in memory .
i have done this .typed the function function in the shell it worked for the session.but next time i do login its not there .
i can i have a... (6 Replies)
Hi I have 2 files a.c and a.bak where I changed long to int using awk script.
I want to get the list of functions whose parameters got modified
for eg: fun ( long a, long b ) might be changed to fun ( int a, int b ) (1 Reply)
Hello,
I'm trying to run a program on a directory (traverse sub dirs too) through my csh script. Arrays support in CSH is appalling, something like associative arrays would have helped me do this so much easier.
Anyway, I want to hold some details extracted from the program and then at the... (0 Replies)
Hi,
Please help me with the below situation where I have to handle the parameters passed to a function in a unique way.
Below is the code, which I am trying to execute. I basically want to pass the parameter to a function, where I am trying to get user input into array(s). I want to name... (7 Replies)
Hi
I would like to place in one line output from two functions. Both functions return text with print cmd.
When I place above code in script it will place them in series.
e.g.
1 #/bin/ksh
2
3 function1()
4 {
5 print "My name is"
6 ... (3 Replies)
Hi ,
I have a script which is using a text file as I/P.
I want a code where it reads n lines from this file and pass the parameters to a function and now this script should run in such a way where a function can be called in parallel with different parameters. Please find below my script, it... (1 Reply)
Hi,
I am a beginner in python programming. In my python script have a main function which calls several other functions. The main function gets its input by reading lines from a input text file. I call the main function for every line in input text file through a loop.
def main(line):
var1... (6 Replies)
Discussion started by: ctrld
6 Replies
LEARN ABOUT REDHAT
universal
UNIVERSAL(3pm) Perl Programmers Reference Guide UNIVERSAL(3pm)NAME
UNIVERSAL - base class for ALL classes (blessed references)
SYNOPSIS
$is_io = $fd->isa("IO::Handle");
$is_io = Class->isa("IO::Handle");
$sub = $obj->can("print");
$sub = Class->can("print");
use UNIVERSAL qw( isa can VERSION );
$yes = isa $ref, "HASH" ;
$sub = can $ref, "fandango" ;
$ver = VERSION $obj ;
DESCRIPTION
"UNIVERSAL" is the base class which all bless references will inherit from, see perlobj.
"UNIVERSAL" provides the following methods and functions:
$obj->isa( TYPE ), CLASS->isa( TYPE ), isa( VAL, TYPE )
C<TYPE> is a package name
$obj is a blessed reference or a string containing a package name
C<CLASS> is a package name
C<VAL> is any of the above or an unblessed reference
When used as an instance or class method ("$obj-"isa( TYPE )>), "isa" returns true if $obj is blessed into package "TYPE" or inherits
from package "TYPE".
When used as a class method ("CLASS-"isa( TYPE )>; sometimes referred to as a static method), "isa" returns true if "CLASS" inherits
from (or is itself) the name of the package "TYPE" or inherits from package "TYPE".
When used as a function, like
use UNIVERSAL qw( isa ) ;
$yes = isa $h, "HASH";
$yes = isa "Foo", "Bar";
or
require UNIVERSAL ;
$yes = UNIVERSAL::isa $a, "ARRAY";
, "isa" returns true in the same cases as above and also if "VAL" is an unblessed reference to a perl variable of type "TYPE", such as
"HASH", "ARRAY", or "Regexp".
$obj->can( METHOD ), CLASS->can( METHOD ), can( VAL, METHOD )
"can" checks if the object or class has a method called "METHOD". If it does then a reference to the sub is returned. If it does not
then undef is returned. This includes methods inherited or imported by $obj, "CLASS", or "VAL".
"can" cannot know whether an object will be able to provide a method through AUTOLOAD, so a return value of undef does not necessarily
mean the object will not be able to handle the method call. To get around this some module authors use a forward declaration (see perl-
sub) for methods they will handle via AUTOLOAD. For such 'dummy' subs, "can" will still return a code reference, which, when called,
will fall through to the AUTOLOAD. If no suitable AUTOLOAD is provided, calling the coderef will cause an error.
"can" can be called as a class (static) method, an object method, or a function.
When used as a function, if "VAL" is a blessed reference or package name which has a method called "METHOD", "can" returns a reference
to the subroutine. If "VAL" is not a blessed reference, or if it does not have a method "METHOD", undef is returned.
VERSION ( [ REQUIRE ] )
"VERSION" will return the value of the variable $VERSION in the package the object is blessed into. If "REQUIRE" is given then it will
do a comparison and die if the package version is not greater than or equal to "REQUIRE".
"VERSION" can be called as either a class (static) method, an object method or or a function.
These subroutines should not be imported via "use UNIVERSAL qw(...)". If you want simple local access to them you can do
*isa = &UNIVERSAL::isa;
to import isa into your package.
perl v5.8.0 2002-06-01 UNIVERSAL(3pm)