Skip to content

Commit bafdbb8

Browse files
Dynamic determine echo method depends on OS for sh
FreeBSD uses "echo" directly, the others use "/bin/echo" Note that no matter which method we use, it won't work on Mac OS. This commit fixed #4.
1 parent e016d15 commit bafdbb8

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

β€ŽREADME.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Make echo colorful with easier method. In [bash](https://www.gnu.org/software/ba
5555

5656
* If you have [lolcat](https://github.com/busyloop/lolcat), you can also try `echo.Rainbow`.
5757
* If you are using Mac OS, please upgrade your bash first, you can use [Homebrew](http://brew.sh/) or [MacPorts](https://www.macports.org/), the origin bash is too old.
58-
* `ksh`/`sh` shell's color echo relys on external `/bin/echo`, it may not work properly with color under BSD and Mac OS.
58+
* `ksh`/`sh` shell's color echo may rely on external `/bin/echo`, it may not work properly with color under BSD and Mac OS.
5959

6060
## Screenshot
6161

β€Žgenerator.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ do
6666
"sh")
6767
fn=
6868
dot=
69-
echo='/bin/echo'
69+
echo='$ECHO'
7070
startSym='{'
7171
endSym='}'
7272
endIf='fi'
@@ -82,6 +82,15 @@ do
8282
fi
8383

8484
echo "#!/usr/bin/env $shell" > "$newDist"
85+
if [ "$shell" = "sh" ]; then
86+
cat << SH_ECHO >> "$newDist"
87+
if [ "\`uname\`" = "FreeBSD" ]; then
88+
ECHO="echo"
89+
else
90+
ECHO="/bin/echo"
91+
fi
92+
SH_ECHO
93+
fi
8594
for color in $(awk '{print $1}' "$table")
8695
do
8796
#light or not

0 commit comments

Comments
Β (0)