Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leading parens incorrectly removed from some case statements #851

Closed
sdball opened this issue Apr 20, 2022 · 2 comments
Closed

Leading parens incorrectly removed from some case statements #851

sdball opened this issue Apr 20, 2022 · 2 comments

Comments

@sdball
Copy link

sdball commented Apr 20, 2022

The following bash is valid in bash 3.2+

_script_dir="$(
	_program="$0"
	case "$_program" in
	(*/*) ;;
	(*) _program=$(command -v -- "$0") ;;
	esac
	[[ -L "$_program" ]] && _program=$(readlink "$_program")
	cd -P -- "$(dirname -- "$_program")" && pwd -P
)"

But shfmt removes the leading parens on the cases which works in bash 4+ but not bash 3

_script_dir="$(
	_program="$0"
	case "$_program" in
	*/*) ;;
	*) _program=$(command -v -- "$0") ;;
	esac
	[[ -L "$_program" ]] && _program=$(readlink "$_program")
	cd -P -- "$(dirname -- "$_program")" && pwd -P
)"
@mvdan
Copy link
Owner

mvdan commented Apr 20, 2022

See the first half of #779, which reported the same issue. In short, this is a consistent formatting choice, and it feels too small and uninteresting to warrant yet another formatting option of its own :)

@sdball
Copy link
Author

sdball commented Apr 20, 2022

Oh thanks for pointing me to the issue. I searched but missed that one.

I agree it's very much an edge, but it means I can't use shfmt on a script that I'd like to continue to work with Bash 3.2.

With the leading parens removed bash 3.2 points to the */*) as invalid

command substitution: syntax error near unexpected token `newline'

I really love shfmt, I think I'll see about rewriting this (admittedly weird) snippet to avoid the issue.

@sdball sdball closed this as completed Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants