Skip to content
Advertisement

Forward slash in Bash on Mac

I have this bash(version 3.2 on MacOS) function

JavaScript

What it’s suppose to do is run phpunit with proper regex, here i am converting * to (.)* and wrapping filter to be case insensitive.

Now

JavaScript

The problem is that parsed command works perfectly fine(matched test cases run), when i run directly at terminal. But it does not when function rtf tries to call it in last line. Somehow phpunit can not find matchings for this.

I can believe that the issue is with forward slash in the $command variable. Can any suggest a fix?

Advertisement

Answer

You should use eval "$command" rather than $command. See following example:

JavaScript

And it’s not safe to write rtf test*fail, instead it should be rtf "test*fail" otherwise test*fail will be expanded to filenames if the pattern matches some files.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement