ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi guys, i got this issue
I have a script which can get one argument, or many. If only one argument then, it call itself with the default behavior, however i can not find the way to call the script within its own body and passing some arguments to it:
This is the body of the decision tree:
Code:
if [ -z "$1" ]
then
echo "Usage: $0 arg_name functions_to_run"
exit
else
if [ $# -le 1 ]
then
echo "0_o Not enough arguments, this function will run at default: $1 func1 func2 func3"
$* $1 func1 func2 func3
exit
else
if [ $# -ge 2 ]
then
FOO=("$@")
for (( i=1; i<=$# -1; i++ ))
do
flujo $1 ${FOO[$i]} &
done
else
echo "o_0 I am a ghost 0_o"
fi
fi
fi
Firstly is 'flujo' a program / command on your machine??
Secondly, please explain this part further:
Quote:
i can not find the way to call the script within its own body
If catkin's response about using recursive nature is what you are after then you would need to do
one of two things (assuming I am getting any of this):
1. Write a wrapper script to call this one and then recursively call yours
2. Wrap the actions in your script into a function and call it recursively from within your script.
yep flujo is a function, which is called several times, with different arguments taken from the input when the script is called
What i was thinking is to made a default behavior, like if you have only one argument, to recall the script with three arguments added besides the first one.
let us say:
Code:
%name_of_script hola
if $# greater that one
then run script as normal
else call script with $1 new_arg1 new_arg2...
I was thinking lazy i know, right now i did an if fork to call the function internally with the arguments for the default operation, considering $#. How ever the doubt assaulted me, recursion for scripts is not possible then, i know the functions can be made recursively though.
No need for the script to call itself again, simply adjust the arguments in this instance (but this is almost certainly not the best way of achieving whatever it is you want to achieve)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.