EnioRM Apr 7, 2017 #1 Hello all. I have a throuble when I try to concatenate some strings in a shell script macro. The script uses sh. Code: root@freebsd:~ # sh [B]# name="john" # name+=" doe"[/B] name+=doe: not found # Can anyone identify where is mistake? Last edited by a moderator: Apr 10, 2017
Hello all. I have a throuble when I try to concatenate some strings in a shell script macro. The script uses sh. Code: root@freebsd:~ # sh [B]# name="john" # name+=" doe"[/B] name+=doe: not found # Can anyone identify where is mistake?
T tobik@ Developer Apr 7, 2017 #2 sh(1) isn't bash and doesn't support +=. You can for example do it like this instead: Code: name="john" name="${name} doe"
sh(1) isn't bash and doesn't support +=. You can for example do it like this instead: Code: name="john" name="${name} doe"
OP EnioRM Apr 7, 2017 Thread Starter #3 Thanks tobik@ So I understood wrong. <https://www.freebsd.org/doc/handbook/shells.html> "FreeBSD comes with several shells, including the Bourne shell (sh(1)) and the extended C shell (tcsh(1)). " I thought that the commands and syntax of SH was similar to Bash. best wishes
Thanks tobik@ So I understood wrong. <https://www.freebsd.org/doc/handbook/shells.html> "FreeBSD comes with several shells, including the Bourne shell (sh(1)) and the extended C shell (tcsh(1)). " I thought that the commands and syntax of SH was similar to Bash. best wishes
SirDice Administrator Staff member Administrator Moderator Apr 10, 2017 #4 EnioRM said: I thought that the commands and syntax of SH was similar to Bash. Click to expand... It's the other way around, Bash syntax is similar to the Bourne Shell (it existed long before bash). And there's a difference between the Bourne shell and the Bourne Again Shell (bash). While technically on FreeBSD /bin/sh is the Almquist Shell. https://en.wikipedia.org/wiki/Almquist_shell https://en.wikipedia.org/wiki/Bourne_shell https://en.wikipedia.org/wiki/Bash_(Unix_shell) I use this site a lot for reference: http://www.grymoire.com/Unix/Sh.html. Stick to that and your script will work on all three shells.
EnioRM said: I thought that the commands and syntax of SH was similar to Bash. Click to expand... It's the other way around, Bash syntax is similar to the Bourne Shell (it existed long before bash). And there's a difference between the Bourne shell and the Bourne Again Shell (bash). While technically on FreeBSD /bin/sh is the Almquist Shell. https://en.wikipedia.org/wiki/Almquist_shell https://en.wikipedia.org/wiki/Bourne_shell https://en.wikipedia.org/wiki/Bash_(Unix_shell) I use this site a lot for reference: http://www.grymoire.com/Unix/Sh.html. Stick to that and your script will work on all three shells.