Is there a way i can pass the arguments as parameters or variables instead of positional arguments to a function, below i am calling the function defined in a script.
Call:
Can I do the call like below, because my call sometimes i would just call with only subject and i don't want to include a log file, sometimes i want to put Cc and sometimes don't want Cc. So I would like to have a better control on how i call or invoke instead of doing positional parameter passing as it would mess up my scripts and lot of maintenance. How do i do that?
For shell functions there is the same parameter passing convention in place as for scripts: you can use positional parameters, meaning that their position define their function - like the first parameter is a name, the second an address, the third a phone number, etc..
You can use options instead, which will work regardless of their position because they are qualified. The following commands will lead to the same values being passed:
Here, the values "aVal", "bVal" and "cVal" are "qualified" by introducing them with certain switches, therefore their position - first, second or third - doesn't matter. There is an utility for decoding such commandlines, which is called getopt/getopts. It is as well an executable as a shell builtin (at least in common shells), both word the same way. I suggest you read the man page of it and ask again if you have further questions.
Hi,
Is there a special positional variables for when using the dot (.)?
Scripts are as below:
$: head -100 x.ksh /tmp/y.ksh
==> x.ksh <==
#!/bin/ksh
#
. /tmp/y.ksh 1234 abcd
echo "yvar1 = $yvar1"
echo "yvar2 = $yvar2"
==> /tmp/y.ksh <==
#!/bin/ksh (2 Replies)
I have a script that uses 2 arguments. I want to call the function part within this script using these same arguments. Below is what I came up with below script so far, any guidance would be helpful. Thank you!
cat backup.sh
#!/bin/bash
function usage {
echo "USAGE: $(basename $0)... (6 Replies)
I need to call a function within a code with $database and $ service as the arguments How do I proceed ? and how would a function be defined and these two arguments would be used inside the function?
calc_pref_avail $database $service
Best regards,
Vishal (7 Replies)
Hi,
I have create a Shell Script, with one function.
I want to call the script file in Java Program.
It working fine. but the problem is the function in the Shell Script is not executed.
Please suggest me,
Regards,
Nanthagopal A (2 Replies)
I have trouble getting this logic to work
#!/bin/bash
function assign_var(){
while
do
read -p "$2 :" $3
done
}
assign_var '$IPADDRESS' ipaddress IPADDRESS
Basicly, i want to make sure that entry is made (i can add more sophisticated checks later), but the idea is to recycle... (11 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)
Hi,
I've a logging function in bourne shell, flog() which logs the first argument passed to it. How can I pass arguments to this function from a file, like
cat filename | sed '...filtering...' | flog
or
cat filename | sed '...filtering...' | xargs flog
Which did not work, after which... (3 Replies)
#include <pthread.h>
#include <signal.h>
...
sigset_t mask;
int err,signo;
err=sigwait(&mask,&signo);
switch(signo){
case SIGINT:
...
}
when I compile above code under solaris 10,it raise following error:
error: too many arguments to function 'sigwait'
I look up signal... (4 Replies)
Hi,
I have a function in shell script
fun1{ echo "No.of arguments are..."}
this function will be called in same script by passing arguments
fun 1 2 3
I want to check the no. of arguments passed to fun1 function in the same functionbefore validation.
can any one suggest me. (2 Replies)
Is it possible to invoke a perl function from a bash script ?
There are existing perl scripts with many functions that I want to reuse from a more recent script written in bash. Hence the question. (1 Reply)