Home > Mobile >  Source command not working in a bash script
Source command not working in a bash script

Time:07-20

Consider this code I run directly in bash (Mac):

> source <(echo "ABC=1")
> echo $ABC
1

Now, if I put these two lines in a test.sh script and execute:

#!/bin/bash
source <(echo "ABC=1")
echo $ABC

nothing is echo'ed, so it looks like source doesn't work? Any ideas?

Btw, I tried replacing source with . - the same problem.

CodePudding user response:

Apple's bash just appears to be too old. I reproduced your failure locally, but it works fine with bash 5.1.16 from homebrew.

I didn't look up any specific bug fixes or version notes, though, sorry.

  •  Tags:  
  • bash
  • Related