argbash icon indicating copy to clipboard operation
argbash copied to clipboard

ZSH support

Open singh1469 opened this issue 7 years ago • 3 comments

Hi

Issue Argbash doesn't seem to support ZSH ?

Symptom When running with ZSH I'm seeing the following error: Error during argument parsing, possibly an Argbash bug

Which points to the eval line below

assign_positional_args ()
{
	# We have an array of variables to which we want to save positional args values.
	# This array is able to hold array elements as targets.
	_positional_names=('_arg_task' )

	for (( ii = 0; ii < ${#_positionals[@]}; ii++))
	do
		eval "${_positional_names[ii]}=\${_positionals[ii]}" || die "Error during argument parsing, possibly an Argbash bug." 1
	done
}

Workaround Runs fine with #!/bin/bash

Many thanks

singh1469 avatar Dec 14 '18 15:12 singh1469

Hello, when generating the output, use -t posix-script. That way, you will get a script without bashisms, but it will only support the POSIX CLI standard, not the GNU one.

matejak avatar Dec 15 '18 11:12 matejak

Perfect, thanks @matejak Closing issue.

singh1469 avatar Dec 18 '18 14:12 singh1469

For anyone, like me, that comes here and has no possibility to run bash on the system: I think the issue is that ZSH handles word splitting differently than BASH. You can force ZSH to split words like bash with setopt shwordsplit - Add this to the beginning of your script and argbash should run on ZSH.

Tested on zsh 5.8.1 (x86_64-ubuntu-linux-gnu) (WSL2)

Very helpful article with explanation: https://scriptingosx.com/2019/08/moving-to-zsh-part-8-scripting-zsh/

le-blue avatar Oct 24 '23 06:10 le-blue