last day (15 days later) » 

19:24
@mikeserv, didn't want to clutter the comments with the output -- here's what the NetBSD /bin/sh gives from some of your examples
shift "$(($#?$#-1:0))"; printf "%s${1+\n}" "$@"
--> arith: syntax error: "3?3-1:0"
${1+":"} return; shift "$((${#}-1))"; printf %s\\n "$@"
--> works as expected
woops, just realized I created this on stackoverflow instead of stackexchange; sorry! not good with chat stuff yet
 
2 hours later…
21:18
@JeffSchaller - no big deal. im not very good at the chat stuff either.
it is weird about the ternary - i guess it doesn't support those. I wonder if it would support shift "$(( ! ! $# * ( $# - 1 ) ))" though...
Still the second one's probably better because it immediately returns and doesn't bother doing any further work if ! $#
21:44
I can try later tonight. Is that two ! in a row ?
(Separated by a space)
user2350426
@Jeff The (logical not of the logical not of $#) is 1 if $# is greater than zero, 0 otherwise. Read it as: "$(( ( ! ! $# ) * ( $# - 1 ) ))"
user2350426
@Jeff Which could be done in a more conventional way like: [ $# -gt 0 ] && printf %s\\n "$@"Not so obfuscated.
22:18
@BinaryZebra - there is nothing obfuscated about simple ANSI C math. But your thing affects the return - and so influences the caller's environment.
That's not necessarily bad - if the function is meant to return false for a no argument condition then ok - but it needs to be expected. In general I wouldn't expect it: ${notset} is not false, and set --; echo "$1" is not false, for example. Your thing also goes pretty haywire for an $IFS of digits.
user2350426
22:51
@JeffSchaller Ooops, sorry, I meant: [ $# -gt 0 ] && shift "$((${#}-1))"; printf %s\\n "$1" which is safer to execute calling a function to preserve the present arguments.
@BinaryZebra - that would cool. i was mainly asking because i dont have a netbsd and was curious about what would or wouldnt work in its arithmetic expressions.
still, in my opinion, eval ought to be preferred for these things - it is much more simple under the hood just to index the last argument than to copy the whole array, shift most of it away, and then to print it.

last day (15 days later) »