0

On Linux I can do:

source <(cat .env | grep ANDROID_GRADLE_TASK)

But on MacOS, this doesn't do anything (no error, and no source)

I have tried to replace -di with --decode --input, it didn't help.

  1. What can I use for MacOS?
  2. Is there a command that works both on Linux (Debian/Ubuntu) and MacOS?
3
  • 1
    What works depends on your shell; this uses Bash syntax, so it will work in Bash on a Mac too; but MacOS now defaults to Zsh for new users.
    – tripleee
    Oct 31, 2022 at 19:08
  • What exactly this does depends on what's in .env; if you need it to be portable between shells, that's a topic we can't answer without seeing the code. (That's a useless cat , by the way.)
    – tripleee
    Oct 31, 2022 at 19:09
  • Actually, for whatever reason, that doesn't seem to work in Bash 3.2 (which is the Bash that I understand macs still have). It does work in zsh, though.
    – ilkkachu
    Oct 31, 2022 at 19:31

1 Answer 1

0

Looks like the only portable way is to do this:

grep ANDROID_GRADLE_TASK .env > .x; source .x

The other option is to install bash 5 from brew on the Mac.

4
  • 2
    That might run, but it won't be very useful. The parts of a pipeline run in subshells, and the point of source is to run in the same shell. E.g. if you try echo foo=bar | source /dev/stdin, you can check that foo does not get set. You might try with lastpipe set, but it doesn't work in interactive shells (though I'm not sure if that's a problem in the context here)
    – ilkkachu
    Oct 31, 2022 at 21:17
  • Odd I tested it just now, worked Oct 31, 2022 at 21:18
  • 1
    ok, right, it does work in zsh. In Bash you'll need lastpipe.
    – ilkkachu
    Oct 31, 2022 at 21:19
  • 1
    source is not portable, it is a bash alias for the standard POSIX . command (change source .x to . .x)
    – terdon
    Oct 31, 2022 at 22:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .