zsh-users
 help / color / mirror / code / Atom feed
* Apple bash to zsh script problems with error control and bash emulation
@ 2020-11-16 15:00 Dominik Reichardt
  2020-11-16 18:01 ` Daniel Shahaf
  0 siblings, 1 reply; 16+ messages in thread
From: Dominik Reichardt @ 2020-11-16 15:00 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 6394 bytes --]

Hi all,

I’ve recently moved to zsh as Apple is pressuring us :)

My problem is that I have built a little bash script thing to work as a buildbot for some projects I’m building snapshots for.

My two problems are that my error control is no longer working in a way that it stops (exit 1) after encountering an error when in bash emulation mode, and that if I deactivate the bash emulation stuff doesn’t work.

My scripts can be found at https://github.com/DominusExult/buildbot <https://github.com/DominusExult/buildbot>, as an example I’ve shortened in this email my exult snapshot.sh and my functions script functions.sh.
Something goes wrong in the error(), pipestatus() and teelog() functions, I guess. But I can’t quite tell and I’ve built that script 5 years ago and am a bit rusty to what each of those function do exactly.

What I expect is that when the script runs into an error it stops, even if the error happens in one of the functions but currently the script goes on and on. This used to work before in bash.
If I get rid of the —emulate sh, my variables don’t get passed on correctly (the error I get in the shorted version of my script is "configure: error: unrecognized option: `-q --disable-data --with-macosx-static-lib-path=/opt/i386/lib’”

I hope you can help me figure this out. I’ve tried researching this on my own but the biggest hurdle was that search results pointed me at bash stuff and not zsh.

Thank you,
Dom

The scripts:

exultsnasphot.sh:
#!/bin/zsh --emulate sh
#functions
. ./functions.sh

headermain EXULT

cd ~/code/snapshots/exult
/usr/bin/git pull --rebase=true 2> >(teelog >&2) || error Git pull

#i386
ARCH=i386
SDK=10.11
DEPLOYMENT=10.7
flags
gcc
CONF_ARGS="-q --disable-data --with-macosx-static-lib-path=/opt/$ARCH/lib"
autogen
build 2>&1 | teelog -a ; pipestatus || return

deploy
{
	#make fat exult binary
	lipo -create -arch arm64 exult_arm64 -arch x86_64 exult_x86_64 -arch i386 exult_i386 -output exult || error lipo
} 2>&1 | teelog -a ; pipestatus || return


functions.sh:
#-------------headers-------------
headermain() {
	if [ "$1" != "" ]; then
		TARGET=$1
		#lowercase of $TARGET
		target="$(echo $TARGET | tr '[A-Z]' '[a-z]')"
		#logfile
		LOGFILE=~/.local/logs/${target}built.txt
	else
		error headermain function
	fi
}

alias deploy='echo -e "$(tput setab 4)$(tput bold)$(tput setaf 3)\tdeployment\t$(tput sgr 0)"'

#-------------Error handling-------------
alias lockfile='rm -f ~/.local/"$TARGET"build1.lockfile'

error () {
	if [ "$?" != "0" ]; then
		if [ "$2" != "" ]; then
			local i2=" $2"
		fi
		if [ "$3" != "" ]; then
			local i3=" $3"
		fi
		echo -e "$(tput setab 1)$(tput bold)$(tput setaf 7)\t${1:-"Unknown Error"}${i2}${i3} failed!\t\t$(tput sgr 0)" 1>&2
		lockfile
		exit 1
	fi
}

pipestatus() {
	local S=("${PIPESTATUS[@]}")
	if test -n "$*"
	then test "$*" = "${S[*]}"
	else ! [[ "${S[@]}" =~ [^0\ ] ]]
	fi
}

teelog() {
	tee $1 $LOGFILE
}

#-------------compiler & flags-------------
flags() {
	SYSARCH=$(uname -m)
	if  [ "$ARCH" = "" ] && [ "$SYSARCH" = "arm64" ]; then
		ARCH=arm64
		SDK=11.0
		DEPLOYMENT=11.0
	elif [ "$ARCH" = "" ] && [ "$SYSARCH" = "x86_64" ]; then
		ARCH=x86_64
		SDK=10.14
		DEPLOYMENT=10.11
	fi

	export PKG_CONFIG_PATH=/opt/$ARCH/lib/pkgconfig
	export PKG_CONFIG=/opt/$SYSARCH/bin/pkg-config

	if [ "$ARCH" = "i386" ]; then
		OPTARCH='-arch i386 -m32 -msse -msse2 -O2 '
	elif [ "$ARCH" = "ppc" ]; then
		OPTARCH='-arch ppc -m32 -O2 '
		export PKG_CONFIG=/opt/x86_64/bin/pkg-config
	elif  [ "$ARCH" = "x86_64" ]; then
		OPTARCH='-m64 -msse -msse2 -O2 '
	elif  [ "$ARCH" = "arm64" ]; then
		OPTARCH='-O2 '
	fi
	OPT=' -w -force_cpusubtype_ALL '$OPTARCH
	SDK=' -isysroot /opt/SDKs/MacOSX'$SDK'.sdk -mmacosx-version-min='$DEPLOYMENT' '
	export MACOSX_DEPLOYMENT_TARGET=$DEPLOYMENT
	export CPPFLAGS='-I/opt/'$ARCH'/include'$SDK
	export CFLAGS='-I/opt/'$ARCH'/include'$SDK' '$OPT
	export CXXFLAGS='-I/opt/'$ARCH'/include '$SDK' '$OPT
	export LDFLAGS='-L/opt/'$ARCH'/lib'$SDK' '$OPT
	export LIBTOOLFLAGS=--silent
}

gcc() {
	if [ "$ARCH" != "" ]; then
		export PATH=/opt/$ARCH/bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
		export LD="/usr/bin/ld"
		export RANLIB="~/code/sh/tools/ranlib"
		if [ "$1" = "legacy" ]; then
			export PATH=/opt/$ARCH/bin/:/opt/xcode3/usr/bin:/opt/xcode3/usr/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
			export CC='/opt/xcode3/usr/bin/llvm-gcc-4.2 -arch '$ARCH
			export CXX='/opt/xcode3/usr/bin/llvm-g++-4.2 -arch '$ARCH
			export LD="/opt/xcode3/usr/bin/ld"
			export RANLIB="/opt/xcode3/usr/bin/ranlib.old"
		elif [ "$1" = "oldgcc" ]; then
			export PATH=/opt/$ARCH/bin/:/opt/xcode3/usr/bin:/opt/xcode3/usr/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
			export CC='/opt/xcode3/usr/bin/gcc-4.2 -arch '$ARCH
			export CXX='/opt/xcode3/usr/bin/g++-4.2 -arch '$ARCH
			export LD="/opt/xcode3/usr/bin/ld"
			export RANLIB="/opt/xcode3/usr/bin/ranlib.old"
		else
			export CC='/usr/bin/clang -arch '$ARCH
			export CXX='/usr/bin/clang++ -arch '$ARCH
		fi
	else
		error gcc function
	fi
}

#-------------command shortcuts-------------
alias autogen='./autogen.sh > /dev/null 2>&1'

alias makes='make clean  > /dev/null ; make -j9 -s AR="~/code/sh/tools/ar" > /dev/null || error $HEADER make'


config() {
	if [ "$CONF_OPT" != "" ]; then
		c1=$CONF_OPT
	fi
	if [ "$CONF_ARGS" != "" ]; then
		c2=$CONF_ARGS
	fi
		
	if [ "$ARCH" = "ppc" ]; then
		./configure --host=powerpc-apple-darwin $CONF_OPT $CONF_ARGS || error $ARCH configure

	elif [ "$ARCH" = "i386" ]; then
		./configure --host=i386-apple-darwin $CONF_OPT $CONF_ARGS || error $ARCH configure

	elif [[ "$ARCH" = "arm64" ]] && [[ "$SYSARCH" != "arm64" ]]; then
		./configure --host=arm-apple-darwin $CONF_OPT $CONF_ARGS || error $ARCH configure

	elif [[ "$ARCH" = "x86_64" ]] && [[ "$SYSARCH" != "x86_64" ]]; then
		./configure --host=x86_64-apple-darwin $CONF_OPT $CONF_ARGS || error $ARCH configure

	else [ "$?" != "0" ]
		./configure $CONF_OPT $CONF_ARGS || error $ARCH configure
	fi
}

stripp() {
	if [ "$ARCH" != "" ]; then
		strip $1 -o $1_$ARCH || error $HEADER strip
	else
		strip $1 -o $1 || error $1 strip
	fi
}

build() {
	config
	makes
	stripp $target
	
}




[-- Attachment #2: Type: text/html, Size: 17364 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Apple bash to zsh script problems with error control and bash emulation
  2020-11-16 15:00 Apple bash to zsh script problems with error control and bash emulation Dominik Reichardt
@ 2020-11-16 18:01 ` Daniel Shahaf
  2020-11-16 18:10   ` Roman Perepelitsa
  2020-11-16 19:45   ` Dominik Reichardt
  0 siblings, 2 replies; 16+ messages in thread
From: Daniel Shahaf @ 2020-11-16 18:01 UTC (permalink / raw)
  To: Dominik Reichardt; +Cc: zsh-users

Dominik Reichardt wrote on Mon, 16 Nov 2020 16:00 +0100:
> I’ve recently moved to zsh as Apple is pressuring us :)
> 

The easiest solution is to keep the script as «#!/usr/bin/env bash»:

https://github.com/zsh-users/zsh/blob/04bd9a44a74683ad0d83921bfb3aa0c4d5992c75/Etc/FAQ.yo#L2056-L2102

> Something goes wrong in the error(), pipestatus() and teelog() functions, I guess. But I can’t quite tell and I’ve built that script 5 years ago and am a bit rusty to what each of those function do exactly.

Well, for starters, $PIPESTATUS doesn't expand to what you think it
does.

> What I expect is that when the script runs into an error it stops, even if the error happens in one of the functions but currently the script goes on and on. This used to work before in bash.

See «set -e».  You probably have it set in your bash global setup.

See also the ERR_RETURN option.

> If I get rid of the —emulate sh, my variables don’t get passed on correctly (the error I get in the shorted version of my script is "configure: error: unrecognized option: `-q --disable-data --with-macosx-static-lib-path=/opt/i386/lib’”
> 

http://zsh.sourceforge.net/FAQ/zshfaq03.html#l18


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Apple bash to zsh script problems with error control and bash emulation
  2020-11-16 18:01 ` Daniel Shahaf
@ 2020-11-16 18:10   ` Roman Perepelitsa
  2020-11-16 19:45   ` Dominik Reichardt
  1 sibling, 0 replies; 16+ messages in thread
From: Roman Perepelitsa @ 2020-11-16 18:10 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: Dominik Reichardt, Zsh Users

[-- Attachment #1: Type: text/plain, Size: 692 bytes --]

On Mon, Nov 16, 2020 at 7:02 PM Daniel Shahaf <d.s@daniel.shahaf.name>
wrote:

> Dominik Reichardt wrote on Mon, 16 Nov 2020 16:00 +0100:
> > I’ve recently moved to zsh as Apple is pressuring us :)
>

Apple is only encouraging users to change their login shell to zsh. You can
still run scripts written in bash, perl, python or what have you.

The easiest solution is to keep the script as «#!/usr/bin/env bash»:
>

This is solid advice. The chance that Apple will make it impossible to run
bash scripts on macOS within the next decade is extremely low. If that
happens (it really won't), then you can decide whether to rewrite the
scripts or to change the OS.

Roman.

[-- Attachment #2: Type: text/html, Size: 1167 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Apple bash to zsh script problems with error control and bash emulation
  2020-11-16 18:01 ` Daniel Shahaf
  2020-11-16 18:10   ` Roman Perepelitsa
@ 2020-11-16 19:45   ` Dominik Reichardt
  2020-11-16 20:11     ` Roman Perepelitsa
  1 sibling, 1 reply; 16+ messages in thread
From: Dominik Reichardt @ 2020-11-16 19:45 UTC (permalink / raw)
  To: zsh-users



> On 16. Nov 2020, at 19:01, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> 
> Dominik Reichardt wrote on Mon, 16 Nov 2020 16:00 +0100:
>> I’ve recently moved to zsh as Apple is pressuring us :)
>> 
> 
> The easiest solution is to keep the script as «#!/usr/bin/env bash»:
> 
> https://github.com/zsh-users/zsh/blob/04bd9a44a74683ad0d83921bfb3aa0c4d5992c75/Etc/FAQ.yo#L2056-L2102

oddly enough, this doesn’t seem to work as expected with my old script on both macOS 10.15 and 11.0. Several things I declare in the function.sh seems as if they don’t exist.
For example that "alias autogen='./autogen.sh > /dev/null 2>&1’”, when I run the script it returns "./exultsnapshot.sh: line 45: autogen: command not found”.
Something changed...

> 
>> Something goes wrong in the error(), pipestatus() and teelog() functions, I guess. But I can’t quite tell and I’ve built that script 5 years ago and am a bit rusty to what each of those function do exactly.
> 
> Well, for starters, $PIPESTATUS doesn't expand to what you think it
> does.

I fixed this behaviour when I turned off bash emulation and used the lower case pipestatus[@] in my function. Seems that didn’t work correctly either way in the bash emulation and thus disturbed my error() function. Now it works again and prints me the error of which command in my build() function failed and then exits the script.

> 
>> What I expect is that when the script runs into an error it stops, even if the error happens in one of the functions but currently the script goes on and on. This used to work before in bash.
> 
> See «set -e».  You probably have it set in your bash global setup.
> 
> See also the ERR_RETURN option.
> 
>> If I get rid of the —emulate sh, my variables don’t get passed on correctly (the error I get in the shorted version of my script is "configure: error: unrecognized option: `-q --disable-data --with-macosx-static-lib-path=/opt/i386/lib’”
>> 
> 
> http://zsh.sourceforge.net/FAQ/zshfaq03.html#l18

Thanks, I have to confess I understood only parts of it, but seems that using $CONF_OPT $CONF_ARGS as ${=CONF_OPT} ${=CONF_ARGS} fixed my woes.

So now the script runs as expected again without bash emulation! Wheee!



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Apple bash to zsh script problems with error control and bash emulation
  2020-11-16 19:45   ` Dominik Reichardt
@ 2020-11-16 20:11     ` Roman Perepelitsa
  2020-11-16 23:15       ` Lewis Butler
  2020-11-17 13:03       ` Dominik Reichardt
  0 siblings, 2 replies; 16+ messages in thread
From: Roman Perepelitsa @ 2020-11-16 20:11 UTC (permalink / raw)
  To: Dominik Reichardt; +Cc: Zsh Users

On Mon, Nov 16, 2020 at 8:46 PM Dominik Reichardt <domiman@gmail.com> wrote:
>
> So now the script runs as expected again without bash emulation! Wheee!

It no longer works with bash though.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Apple bash to zsh script problems with error control and bash emulation
  2020-11-16 20:11     ` Roman Perepelitsa
@ 2020-11-16 23:15       ` Lewis Butler
  2020-11-17  7:08         ` Roman Perepelitsa
  2020-11-17 13:03       ` Dominik Reichardt
  1 sibling, 1 reply; 16+ messages in thread
From: Lewis Butler @ 2020-11-16 23:15 UTC (permalink / raw)
  To: Zsh Users

On 16 Nov 2020, at 13:11, Roman Perepelitsa <roman.perepelitsa@gmail.com> wrote:
> On Mon, Nov 16, 2020 at 8:46 PM Dominik Reichardt <domiman@gmail.com> wrote:
>> 
>> So now the script runs as expected again without bash emulation! Wheee!
> 
> It no longer works with bash though.

Are you using the Apple-supplied bash or bash from home-brew )or similar)?

Apple-supplied Bash is very old (3.2).


-- 
ɹןʇnqן
<mailto:lbutler@covisp.net>
tel:+1.303.219.0564





^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Apple bash to zsh script problems with error control and bash emulation
  2020-11-16 23:15       ` Lewis Butler
@ 2020-11-17  7:08         ` Roman Perepelitsa
  0 siblings, 0 replies; 16+ messages in thread
From: Roman Perepelitsa @ 2020-11-17  7:08 UTC (permalink / raw)
  To: Lewis Butler; +Cc: Zsh Users

On Tue, Nov 17, 2020 at 12:16 AM Lewis Butler <lbutler@covisp.net> wrote:
>
> On 16 Nov 2020, at 13:11, Roman Perepelitsa <roman.perepelitsa@gmail.com> wrote:
> > On Mon, Nov 16, 2020 at 8:46 PM Dominik Reichardt <domiman@gmail.com> wrote:
> >>
> >> So now the script runs as expected again without bash emulation! Wheee!
> >
> > It no longer works with bash though.
>
> Are you using the Apple-supplied bash or bash from home-brew )or similar)?

${=CONF_OPT} is invalid in all versions of bash, so the script doesn't
work in bash regardless of how bash was installed.

Originally Dom had a script that worked on any machine that has bash
installed. Now he has a script that works on any machine that has zsh
installed. Crucially, whether the script works or not doesn't depend
on how (from which shell) you invoke it.

Roman.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Apple bash to zsh script problems with error control and bash emulation
  2020-11-16 20:11     ` Roman Perepelitsa
  2020-11-16 23:15       ` Lewis Butler
@ 2020-11-17 13:03       ` Dominik Reichardt
  2020-11-17 15:54         ` Lewis Butler
  1 sibling, 1 reply; 16+ messages in thread
From: Dominik Reichardt @ 2020-11-17 13:03 UTC (permalink / raw)
  To: Zsh Users



> On 16. Nov 2020, at 21:11, Roman Perepelitsa <roman.perepelitsa@gmail.com> wrote:
> 
> On Mon, Nov 16, 2020 at 8:46 PM Dominik Reichardt <domiman@gmail.com> wrote:
>> 
>> So now the script runs as expected again without bash emulation! Wheee!
> 
> It no longer works with bash though.

I’m good with that. I needed the script to work on my machines that are now all switched to zsh shell. If I really need it to work with bash again, I can retrace my steps as I “documented” my steps with GitHub commits.
The biggest hurdle was that somehow the scripts stopped working correctly when I kept with “… env bash”, so having them work in zsh only is ok for me.

Thanks again all!

Dom

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Apple bash to zsh script problems with error control and bash emulation
  2020-11-17 13:03       ` Dominik Reichardt
@ 2020-11-17 15:54         ` Lewis Butler
  2020-11-17 16:13           ` Dominik Reichardt
  0 siblings, 1 reply; 16+ messages in thread
From: Lewis Butler @ 2020-11-17 15:54 UTC (permalink / raw)
  To: Zsh Users

On 17 Nov 2020, at 06:03, Dominik Reichardt <domiman@gmail.com> wrote:
> On 16. Nov 2020, at 21:11, Roman Perepelitsa <roman.perepelitsa@gmail.com> wrote:
>> On Mon, Nov 16, 2020 at 8:46 PM Dominik Reichardt <domiman@gmail.com> wrote:
>>> So now the script runs as expected again without bash emulation! Wheee!

>> It no longer works with bash though.

> I’m good with that. I needed the script to work on my machines that are now all switched to zsh shell.

This statement seems to me to have a underlying assumption that is entirely wrong.

Bash did not go away and bash will not go away. The shell you use interactively has nothing to do with the shell a script invokes.

There is no reason to change a working script from bash to zsh just because the interactive shell you use has changed.

There may be other reasons to change a script for new features or better behavior (For example, I converted many sh scripts to bash because of these types of issues, but I also still have plenty of sh scripts as well).


-- 
ɹןʇnqן
<mailto:lbutler@covisp.net>
tel:+1.303.219.0564





^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Apple bash to zsh script problems with error control and bash emulation
  2020-11-17 15:54         ` Lewis Butler
@ 2020-11-17 16:13           ` Dominik Reichardt
  2020-11-17 21:29             ` Roman Perepelitsa
  2020-11-19 13:31             ` Lewis Butler
  0 siblings, 2 replies; 16+ messages in thread
From: Dominik Reichardt @ 2020-11-17 16:13 UTC (permalink / raw)
  To: Zsh Users



> On 17. Nov 2020, at 16:54, Lewis Butler <lbutler@covisp.net> wrote:
> 
> 
> On 17 Nov 2020, at 06:03, Dominik Reichardt <domiman@gmail.com> wrote:
>> On 16. Nov 2020, at 21:11, Roman Perepelitsa <roman.perepelitsa@gmail.com> wrote:
>>> On Mon, Nov 16, 2020 at 8:46 PM Dominik Reichardt <domiman@gmail.com> wrote:
>>>> So now the script runs as expected again without bash emulation! Wheee!
> 
>>> It no longer works with bash though.
> 
>> I’m good with that. I needed the script to work on my machines that are now all switched to zsh shell.
> 
> This statement seems to me to have a underlying assumption that is entirely wrong.
> 
> Bash did not go away and bash will not go away. The shell you use interactively has nothing to do with the shell a script invokes.
> 
> There is no reason to change a working script from bash to zsh just because the interactive shell you use has changed.
> 
> There may be other reasons to change a script for new features or better behavior (For example, I converted many sh scripts to bash because of these types of issues, but I also still have plenty of sh scripts as well).


Let me rephrase it:
I switched my interactive shell to zsh on all my machines. 

My script did no longer work correctly even though the script invoked bash (Apple’s old bash).

My script did not work correctly when I changed it to invoke zsh with bash emulation.

My script did work correctly after I changed ti to invoke zsh without bash emulation and some fixes to make it work.

So now I am happy that my script works on all my machines. And from that list, I think it is clear that it was not working at least not with Apple’s bash and whatever they did to make it work less than it did before I switched to zsh. My goal was that I can use the script on a new machine without having to install a proper bash first. And that goal is met, so thank you for your input and that you are willing to help.

Dom


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Apple bash to zsh script problems with error control and bash emulation
  2020-11-17 16:13           ` Dominik Reichardt
@ 2020-11-17 21:29             ` Roman Perepelitsa
  2020-11-17 21:47               ` Bart Schaefer
  2020-11-19 13:31             ` Lewis Butler
  1 sibling, 1 reply; 16+ messages in thread
From: Roman Perepelitsa @ 2020-11-17 21:29 UTC (permalink / raw)
  To: Dominik Reichardt; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 1007 bytes --]

On Tue, Nov 17, 2020 at 5:14 PM Dominik Reichardt <dominik@reichardt.de>
wrote:

>
> I switched my interactive shell to zsh on all my machines.
>
> My script did no longer work correctly even though the script invoked bash
> (Apple’s old bash).
>

It's unlikely that the first event has caused the second. In other words,
if you were to do all the same things all over again but *not* switch your
interactive shell to zsh, the bash script would still stop working. My
guess is that you've upgraded macOS, which in turn has caused bash to
downgrade from 5.x to 3.3.

So now I am happy that my script works on all my machines.


I'm glad. If some of your machines are expected to have bash over 10 years
old, it's reasonable to avoid invoking bash in your scripts. I sympathise.
I happen to maintain a few POSIX shell scripts and macOS has really been a
bane with its /bin/sh symlinked to bash 3.3. Writing workarounds for bash
bugs fixed over a decade ago is frustrating.

Roman.

[-- Attachment #2: Type: text/html, Size: 1484 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Apple bash to zsh script problems with error control and bash emulation
  2020-11-17 21:29             ` Roman Perepelitsa
@ 2020-11-17 21:47               ` Bart Schaefer
  2020-11-17 22:25                 ` Dominik Reichardt
  2020-11-18 10:01                 ` Roman Perepelitsa
  0 siblings, 2 replies; 16+ messages in thread
From: Bart Schaefer @ 2020-11-17 21:47 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Dominik Reichardt, Zsh Users

[-- Attachment #1: Type: text/plain, Size: 363 bytes --]

On Tue, Nov 17, 2020, 1:29 PM Roman Perepelitsa <roman.perepelitsa@gmail.com>
wrote:

>
> My guess is that you've upgraded macOS, which in turn has caused bash to
> downgrade from 5.x to 3.3.
>

On Catalina bash is actually 3.2.57, it appears.  Why on earth ... oh well.

ksh is at least from 2012, could experiment running the pre-zsh-ized
scripts with that.

>

[-- Attachment #2: Type: text/html, Size: 970 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Apple bash to zsh script problems with error control and bash emulation
  2020-11-17 21:47               ` Bart Schaefer
@ 2020-11-17 22:25                 ` Dominik Reichardt
  2020-11-18 10:01                 ` Roman Perepelitsa
  1 sibling, 0 replies; 16+ messages in thread
From: Dominik Reichardt @ 2020-11-17 22:25 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 845 bytes --]

Bart Schaefer <schaefer@brasslantern.com> schrieb am Di. 17. Nov. 2020 um
22:48:

> On Tue, Nov 17, 2020, 1:29 PM Roman Perepelitsa <
> roman.perepelitsa@gmail.com> wrote:
>
>>
>> My guess is that you've upgraded macOS, which in turn has caused bash to
>> downgrade from 5.x to 3.3.
>>
>
> On Catalina bash is actually 3.2.57, it appears.  Why on earth ... oh well.
>
> ksh is at least from 2012, could experiment running the pre-zsh-ized
> scripts with that.
>

Apple can't (or rather won't) use newer bash than 3.2.57 due to licensing
woes (GPL3) that's why they want users to switch to zsh and why macOS
10.15+ now use zsh by default for new users.
So while I DID upgrade my main machine I doubt that Apple downgraded my
bash.

I'll have to try with a different machine with an older macOS to verify
that on those this all behaves similar

>

[-- Attachment #2: Type: text/html, Size: 2253 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Apple bash to zsh script problems with error control and bash emulation
  2020-11-17 21:47               ` Bart Schaefer
  2020-11-17 22:25                 ` Dominik Reichardt
@ 2020-11-18 10:01                 ` Roman Perepelitsa
  1 sibling, 0 replies; 16+ messages in thread
From: Roman Perepelitsa @ 2020-11-18 10:01 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Dominik Reichardt, Zsh Users

On Tue, Nov 17, 2020 at 10:48 PM Bart Schaefer
<schaefer@brasslantern.com> wrote:
>
> On Catalina bash is actually 3.2.57, it appears.  Why on earth ... oh well.

Right, that one. The last 3.x release. If this release were a person,
it would be in high school by now.

On Tue, Nov 17, 2020 at 11:26 PM Dominik Reichardt <domiman@gmail.com> wrote:
>
> So while I DID upgrade my main machine I doubt that Apple downgraded my bash.

My guess is that you'd previously installed bash with homebrew or
similar, so the script was being interpreted with bash 5.x. After the
upgrade it started being interpreted with the stock bash (3.x). Does
that sound plausible?

It's a good idea to install the newer bash (e.g., with homebrew) and
to point /bin/sh to it. Having an ancient sh interpreter is bound to
create friction.

Roman.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Apple bash to zsh script problems with error control and bash emulation
  2020-11-17 16:13           ` Dominik Reichardt
  2020-11-17 21:29             ` Roman Perepelitsa
@ 2020-11-19 13:31             ` Lewis Butler
  2020-11-19 13:55               ` Dominik Reichardt
  1 sibling, 1 reply; 16+ messages in thread
From: Lewis Butler @ 2020-11-19 13:31 UTC (permalink / raw)
  To: Zsh Users

On 17 Nov 2020, at 09:13, Dominik Reichardt <dominik@reichardt.de> wrote:
> On 17. Nov 2020, at 16:54, Lewis Butler <lbutler@covisp.net> wrote:
>> 
>> There is no reason to change a working script from bash to zsh just because the interactive shell you use has changed.
>> 
>> There may be other reasons to change a script for new features or better behavior (For example, I converted many sh scripts to bash because of these types of issues, but I also still have plenty of sh scripts as well).
> 
> 
> Let me rephrase it:
> I switched my interactive shell to zsh on all my machines. 
> 
> My script did no longer work correctly even though the script invoked bash (Apple’s old bash).

Most like that would be because you did not have the same version of bash. If you installed bash via a port manager, you were running bash 5. The bash that comes with macOS is 3.2. this is almost certainly the root cause of all your issues with the scrip

> My script did work correctly after I changed ti to invoke zsh without bash emulation and some fixes to make it work.

That's good, glad it is working now. But the issue of bash versions is one to keep in mind, as bash3.2 is very very old (2005?) and most bash scripts use at least some of the fixes and improvements in bash 4.x even if they haven't adopted bash 5.x changes.

I would recommend having bash5 installed as you are likely to run into other people's code that is written for bash 4.x

-- 
ɹןʇnqן
<mailto:lbutler@covisp.net>
tel:+1.303.219.0564





^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Apple bash to zsh script problems with error control and bash emulation
  2020-11-19 13:31             ` Lewis Butler
@ 2020-11-19 13:55               ` Dominik Reichardt
  0 siblings, 0 replies; 16+ messages in thread
From: Dominik Reichardt @ 2020-11-19 13:55 UTC (permalink / raw)
  To: Zsh Users



> On 19. Nov 2020, at 14:31, Lewis Butler <lbutler@covisp.net> wrote:
> 
> 
> On 17 Nov 2020, at 09:13, Dominik Reichardt <dominik@reichardt.de> wrote:
>> On 17. Nov 2020, at 16:54, Lewis Butler <lbutler@covisp.net> wrote:
>>> 
>>> There is no reason to change a working script from bash to zsh just because the interactive shell you use has changed.
>>> 
>>> There may be other reasons to change a script for new features or better behavior (For example, I converted many sh scripts to bash because of these types of issues, but I also still have plenty of sh scripts as well).
>> 
>> 
>> Let me rephrase it:
>> I switched my interactive shell to zsh on all my machines.
>> 
>> My script did no longer work correctly even though the script invoked bash (Apple’s old bash).
> 
> Most like that would be because you did not have the same version of bash. If you installed bash via a port manager, you were running bash 5. The bash that comes with macOS is 3.2. this is almost certainly the root cause of all your issues with the scrip

I have to concede the point. I was not able to make the original script run on any prior macOS version in the 3.2x bash provided by apple. So I MUST have used bash provided by MacPorts but on some migration to a newer macOS must have lost that and completely forgot about it, too.

> 
>> My script did work correctly after I changed ti to invoke zsh without bash emulation and some fixes to make it work.
> 
> That's good, glad it is working now. But the issue of bash versions is one to keep in mind, as bash3.2 is very very old (2005?) and most bash scripts use at least some of the fixes and improvements in bash 4.x even if they haven't adopted bash 5.x changes.
> 
> I would recommend having bash5 installed as you are likely to run into other people's code that is written for bash 4.x
> 

I’ll keep it in mind when I run into problems. If I install it proactively, I will just forget again why I did it :)

Cheers,
Dom


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2020-11-19 13:55 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-16 15:00 Apple bash to zsh script problems with error control and bash emulation Dominik Reichardt
2020-11-16 18:01 ` Daniel Shahaf
2020-11-16 18:10   ` Roman Perepelitsa
2020-11-16 19:45   ` Dominik Reichardt
2020-11-16 20:11     ` Roman Perepelitsa
2020-11-16 23:15       ` Lewis Butler
2020-11-17  7:08         ` Roman Perepelitsa
2020-11-17 13:03       ` Dominik Reichardt
2020-11-17 15:54         ` Lewis Butler
2020-11-17 16:13           ` Dominik Reichardt
2020-11-17 21:29             ` Roman Perepelitsa
2020-11-17 21:47               ` Bart Schaefer
2020-11-17 22:25                 ` Dominik Reichardt
2020-11-18 10:01                 ` Roman Perepelitsa
2020-11-19 13:31             ` Lewis Butler
2020-11-19 13:55               ` Dominik Reichardt

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).