Assuming you're using Bash as your shell, this is the ideal situation for the case statement. Consider the following example:
Here the script reads all the parameters one at a time from the file data.txt, and if they start with a lower- or upper-case J or M the appropriate function is called. If the parameter under consideration starts with any other character whatsoever, no function is called, and the script moves right on to the next parameter in the file, continuing in this manner until it reaches the end.
How to get exit value of an executable that gets called from function?
I have an executable called “myexec” which returns 0 on success and different values for different fail scenarios.
I need to call this (myexec) executable from “myprog()” function of other executable and get the exit value... (1 Reply)
Hi ,
I have three funcions f1, f2 and f3 .
f1 calls f2 and f2 calls f3 .
I have a global variable "period" which i want to pass to f3 .
Can i pass the variable directly in the definition of f3 ?
Pls help .
sars (4 Replies)
Hello,
I am new to unix hence struggling with my requirement.
I have a string like :
ECR/CHQ/GBP/12345.out
I need to get only the ECR/CHQ/GBP portion of the string(cut the string based on the third occurrence of / )...How do it do it?
Many thanks (3 Replies)
Hello Experts,
I am building a shell where I need to use case structure. The structure is in a function as in the sample code below:
# Shell mySh
#!/bin/sh
doThis(){
var=$1
case "$var" in
IT)
echo "ok 1 $var"
;;
... (7 Replies)
Hi Guys,
I am trying to pass arguments to the script i am wrinting.
When no argument is passed or wrong argument is passed, the script needs to output the way it needs to be called and exit.
Currently, when no arguments is passed, it is not getting exited but goes on assuming those... (3 Replies)
We have a program source C and is required to indicate how many times each function is called from the C program. also print the line number where there is a call.
I've tried something like this:
#!/bin/sh
for i in $*;do
if !
then
echo $i is not a C file.
else echo $i... (0 Replies)
Good day, I am a newbie here and thanks for accepting me
I have a task to modify input data where my input data looks like
123|34567|CHINE
1|23|INDIA
34512|21|USA
104|901|INDIASee that my input has two columns with different character length but max length is 5 and minimum length is 0 which... (1 Reply)
I have the below script which creates a directory or simply terminates without throwing error (exit 1) incase the directory exists.
bash-4.1$ vi mdir.sh
#!/bin/bash -e
shopt -s expand_aliases
alias mkdir=mkdir_s
mkdir_s(){
if ]; then
echo " directory EXISTS "
return
else
echo "... (3 Replies)
Hello,
I have this awk code in a bash script to perform a find and replace task. This finds one unique line in a file and substitutes the found line with a replacement.
#! /bin/bash
# value determined elsewhere
total_outputs_p1=100
# file being modified... (5 Replies)
Discussion started by: LMHmedchem
5 Replies
LEARN ABOUT PHP
xml_set_element_handler
XML_SET_ELEMENT_HANDLER(3) 1 XML_SET_ELEMENT_HANDLER(3)xml_set_element_handler - Set up start and end element handlersSYNOPSIS
bool xml_set_element_handler (resource $parser, callable $start_element_handler, callable $end_element_handler)
DESCRIPTION
Sets the element handler functions for the XML $parser. $start_element_handler and $end_element_handler are strings containing the names
of functions that must exist when xml_parse(3) is called for $parser.
PARAMETERS
o $parser
- A reference to the XML parser to set up start and end element handler functions.
o $start_element_handler
- The function named by $start_element_handler must accept three parameters:
start_element_handler (resource $parser, string $name, array $attribs)
o $parser
- The first parameter, parser, is a reference to the XML parser calling the handler.
o $name
- The second parameter, $name, contains the name of the element for which this handler is called.If case-folding is in
effect for this parser, the element name will be in uppercase letters.
o $attribs
- The third parameter, $attribs, contains an associative array with the element's attributes (if any).The keys of this
array are the attribute names, the values are the attribute values.Attribute names are case-folded on the same criteria as
element names.Attribute values are not case-folded. The original order of the attributes can be retrieved by walking
through $attribs the normal way, using each(3).The first key in the array was the first attribute, and so on.
Note
Instead of a function name, an array containing an object reference and a method name can also be supplied.
o $end_element_handler
- The function named by $end_element_handler must accept two parameters:
end_element_handler (resource $parser, string $name)
o $parser
- The first parameter, parser, is a reference to the XML parser calling the handler.
o $name
- The second parameter, $name, contains the name of the element for which this handler is called.If case-folding is in
effect for this parser, the element name will be in uppercase letters.
If a handler function is set to an empty string, or FALSE, the handler in question is disabled.
RETURN VALUES
Returns TRUE on success or FALSE on failure.
PHP Documentation Group XML_SET_ELEMENT_HANDLER(3)