0

I am writing a bash script on my mac and when I call a function with the open command it gets stuck in a loop.

For example:

function (){
   open https://www.example.com
}

I have tried putting some echo commands in between the open command to see what happens.

If I do the following:

function (){
   echo "checkpoint 1"
   open https://www.example.com
   echo "checkpoint 2"
}

I get the following output:

checkpoint 1
checkpoint 1
checkpoint 1
checkpoint 1...

If I isolate the command outside of the function then the script behaves as expected.

Any help is greatly appreciated.

  • Do you have another function called open? Check with functions open or typeset -f open in the zsh shell (which is the shell I'm assuming you're using as you are using anonymous functions). I can not reproduce the behavior that you describe. – Kusalananda Dec 25 '21 at 20:31
  • 1
    Is your function really defined like that? It's a syntax error in bash. Perhaps you called the function open (and thus have open() calling itself), in which case you can use command open within the function. @they, from https://stackoverflow.com/q/264395, it seems that open is a command similar to xdg-open. – rowboat Dec 26 '21 at 02:38
  • @rowboat Anonymous functions are allowed in zsh. I don't see the use of it here, but the syntax is correct for zsh. I know what open is on macOS (I have access to macOS too). I was mostly wondering whether the anonymous function was called from within another function named open. – Kusalananda Dec 26 '21 at 07:14
  • I did in fact have the function named open. I completely overlooked this possibility. When I rename the function it now works! – Daniel Booth Dec 28 '21 at 13:28

0 Answers0