mercredi 6 mai 2020

Bash - appending options to a defined function in an if statement?

I've written a short script to undertake a task for a project I'm working on. The jist is its two functions with the options preconfigued and an if statement setting which way to go. However, there's potentially more variables that I'd need to account for in this, I figured I can do this adding another parameter. However what I haven't figured is the extra functions I'd need to configure

So the formula looks a little like this:

    function1 () {
       foo $1 $2 -etc -etc -etc} 
    function2 () {
       foo $1 $2 -cte -cte -cte}
    if [ X = Y ] 
    then $(function1 $1 $2)
    else $(function2 $1 $2)

I could simply expand this by defining more functions, however as the additional formulas are likely to be the same, though with one or two options added on, what I'm wondering is if, instead of writing out multiple functions, its possible to simply append options onton the previous function during the if statment.

I have no idea how this should be, but for demonstrative sake let's say something like this:

if [ X = Y ] && [ Y = Z ]
then $(function1 $1 $2 '--optionA')
else $(function1 $1 $2)

Aucun commentaire:

Enregistrer un commentaire