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 HPUX
ch_rc
ch_rc(1M)ch_rc(1M)NAME
ch_rc - change system configuration file
SYNOPSIS
root] {parameter|parameter=value}...] [file...]
DESCRIPTION
manages the addition, modification, removal, and retrieval of information stored in files having the format of those in the directory.
Parameter names are treated as strings. Thus, has no special meaning to in relation to other parameters named
Options
file Specify the file(s) to be used as the configuration database. If no file is specified, the set of files used by defaults
to and all files in the directory.
Modification and deletion of configuration parameters occurs in the file where the parameter is found.
Add or modify a parameter definition. For each parameter specified
on the command line, if the parameter is found in the specified (or default) files, it is modified to reflect the speci-
fied value. If the parameter is not found, it is added to the specified file(s).
If a new parameter is being defined, one or more files must be specified on the command line; the specified files are
those in which the parameter will be defined.
Remove a parameter definition. For each parameter name specified
on the command line, remove any occurrence of that parameter from the specified file(s).
List configuration values. For each parameter specified on the
command line, output every definition of the parameter from the specified file(s). Output consists of only the values,
one per line.
Specify a parameter name or name/value pair. If a name and value
is expected, but only a name is specified, the value will be set to the empty string. For example, specifying or will
result in and respectively.
Due to shell quoting rules, if you need a quoted parameter value, you must protect the quotes from the shell. For exam-
ple,
yields:
which is an error, whereas,
yields:
Verbose. When used with the
option, the option causes a verbose listing to be output. This listing includes a filename followed by the entire line
containing the specified parameter for each occurrance of the parameter.
The option is used to list all occurances of array parameters matching the parameters specified on the command line.
For example,
may emit the following output:
Normally, the files specified on the command line are used as specified.
By specifying a root directory with the option, all files (including the default files if none are specified) will be
interpreted relative to root.
For example, if root is specified as and is specified on the command line, it will be interpreted as
RETURN VALUE
exits with one of the following values:
0 add/delete/list successful
1 command line syntax/usage error
2 can not access one or more of the listed (or default) files
3 can not open/create/write file
4 memory error
5 no files specified on command line for add option
EXAMPLES
Files in the directory have the following format:
WARNINGS
does not interpret configuration files; it only does pattern matching. As a result, if comments appear on lines containing parameter defi-
nitions, the comments will also appear in output when using the option.
cannot parse multiple parameter definitions which occur on the same line of a file.
AUTHOR
was developed by HP.
FILES
system configuration database driver file
directory containing system configuration files
SEE ALSO rc.config(4).
ch_rc(1M)