You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
This has bitten me multiple times, not sure if there is a good place for it in the book?
When a function accepts optional parameters for arg1, and arg2, and unlimited additional parameters, this may look okay, but it does not work, use arg1, arg2, shift 2, then read remaining args in from $@
local a="$1" b="$2"
shift 2
local c="$@"
The desired effect is not achieved, because shift 2 doesn't shift any, and returns signal 1 (usually without detection), If only one or zero args are provided to the function. It's a mess to debug.
This sets a and b to arg1 and arg2, and c to any remaining data, without any error signals, even if there are no args:
local a="$1" b="$2"
shift 2 || shift || true
local c="$@"
I was wondering if anyone has a less messy way to achieve that desired effect?
The text was updated successfully, but these errors were encountered:
This has bitten me multiple times, not sure if there is a good place for it in the book?
When a function accepts optional parameters for arg1, and arg2, and unlimited additional parameters, this may look okay, but it does not work, use arg1, arg2, shift 2, then read remaining args in from $@
The desired effect is not achieved, because
shift 2
doesn't shift any, and returns signal 1 (usually without detection), If only one or zero args are provided to the function. It's a mess to debug.This sets a and b to arg1 and arg2, and c to any remaining data, without any error signals, even if there are no args:
I was wondering if anyone has a less messy way to achieve that desired effect?
The text was updated successfully, but these errors were encountered: