Re: IFS=:; ${-+:foo:var} skips the first empty element
Thorsten Glaser tg at mirbsd.de writes: mirabilos - This has been the case since mksh R17, youb notice this. Ib issue and the bugs fixed that introduced this issue were *much* worse. (Sorry about that. Need to be realistic here. I did spend hours yesternight on this.) Thank you for your hard work. I once remarked to you that it must be a lonely road - I hope I was wrong. No problem, hope youb So far so good. Seems on par with dash's quickness and far more capable. I just wish I could get to the next line with CTRL-V CTRL-J. It's a stupid habit I picked up rather than using a proper editor. Guess it's time to break that habit, anyway. I do particularly like the dex editor, though. https://github.com/tihirvon/dex An aside to the two of you: Googlemail has issues with greylisting. Mails from you may reach my server with weeks delay or not at all. Posting through GMane should be fine, though b which Lars still has not fixed. Right. A comparison to ATT ksh93 shows that: mksh$ typeset -p nq typeset nq=space ksh93$ typeset -p nq nq=$'spacedivdedargument\nhere' Everything else is the same though. (GNU bash behaves like ATT ksh93, and with dash all hopes are off, anyway.) I think I might be reporting the dash bug myself, as soon as I can narrow it down. I have discovered one weird behavior surrounding this sort of thing in that shell, though. In any case, any portable bit that I try to write can be done as simply as s=$*. It's a little weird, maybe, but seems to be equally respected in every shell I've tried. This is not a difficult workaround by any means. mksh$ b=${a//[! ]}; echo ${#b} 3 This also works in GNU bash and ATT ksh93. I know, but it's where it doesn't work that bugs me. This is alright. I just really hate some parts of POSIXb and it doesnb cases is not straightforward, in the existing codebase. I've been experimenting with writing out a shell sourceable argument array that I can call on from any shell. Here's one way I *think* I have managed to get everyone to cooperate: It's a bit long, so don't get impatient. I think it's pretty simple though. qchk() { $1 -s -- $@ ; } \SCRIPT sq() ( chkpr() { case $# in (0) case ${ZSH_VERSION:+?} in (?) emulate sh;; esac ;; (1) case $1 in ([!\']*) spl $1 ;; (\'*)case ${KSH_VERSION} in (*MIRBSD*) spl '$1 ;; (*) spl $1 ;; esac ;; (*) printf '' ;; esac ;; (*) return 1;; esac } spl() { IFS=\' ; set -f ; set -- $* printf \'%s $1 ; shift printf '''%s $@ printf ' } chkpr while [ $# -gt 0 ] do chkpr $1 shift ; done ; echo ) shift ; sq $@ SCRIPT printf '%s\n\n' * for sh in mk z ya da ba '' do echo ${sh}sh qchk ${sh}sh * '' eval [ -e $(qchk ${sh}sh *) ] echo hooray! echo done So far it caters to three shells' peculiarities, though I have no doubt that list will grow as I discover them, and I don't have a ksh93 to work with. 2 are obvious - zsh and mksh - in the chkpr() function. But one that is less so is dash. I should be able to do: ... printf '''%s $@' ... But dash gets upset and so I need the next line. Anyway, regarding mksh, I have only to check if the very first split char is the split delimiter, and, if so, add another. It isn't difficult to do. The sequence above puts this on my screen when run from my test directory: '' horribly misguided filename''\\\and so on mksh '\''' horribly misguided filename'\'''\'''\'''\'''\'''\''\\\and so on' '' hooray! zsh '\''' horribly misguided filename'\'''\'''\'''\'''\'''\''\\\and so on' '' hooray! yash '\''' horribly misguided filename'\'''\'''\'''\'''\'''\''\\\and so on' '' hooray! dash '\''' horribly misguided filename'\'''\'''\'''\'''\'''\''\\\and so on' '' hooray! bash '\''' horribly misguided
Re: IFS=:; ${-+:foo:var} skips the first empty element
michael dixit: So far so good. Seems on par with dash's quickness and far more capable. I Right. More robust (and less buggy), too. just wish I could get to the next line with CTRL-V CTRL-J. It's a stupid There is no “next line” in mksh, at least not interactively. But with ^Xe, you can spawn an editor on the current input line, and writing and sending multiline input there should™ work. (Disclaimer: only somewhat tested, amounting to what $PS2 does.) habit I picked up rather than using a proper editor. Guess it's time to break that habit, anyway. I do particularly like the dex editor, though. You won’t win me over, what with jupp and all that ;-) (And if there’s no jupp, I just use ed.) This also works in GNU bash and ATT ksh93. I know, but it's where it doesn't work that bugs me. Sure. It’s just that ATT ksh93 is the model for most of mksh’s behaviour, and GNU bash is something to keep in the eye as it’s what GNU users expect, which is why I mentioned it. I've been experimenting with writing out a shell sourceable argument array that I can call on from any shell. Here's one way I *think* I have managed Oh *wow*. I tend to keep my scripts mksh-specific (but portable across systems) and the shell portable, not the scripts portable to various shells… living without certain amenities, especially arrays often, makes me crazy ;) So far it caters to three shells' peculiarities, though I have no doubt that list will grow as I discover them, and I don't have a ksh93 to work with. 2 Right. For example, avoid printf(1) on mksh, but use the print builtin (on all Korn shells). ksh93, for small test things, is available though shbot on Freenode IRC. Example: 20:26⎜shbot k# echo ${.sh.version} 20:26⎜[[shbot]] Version AJM 93u+ 2012-08-01 The first line is me writing /msg shbot k# echo ${.sh.version} and the second line is shbot running ksh93 -'EOF' echo ${.sh.version} EOF in a VM, displaying its output. Anyway, regarding mksh, I have only to check if the very first split char is the split delimiter, and, if so, add another. It isn't difficult to do. The If this is about the bug you reported, it’s unwise to do this by a check on the shell, as the bug is likely to eventually get fixed, making your code buggy ;-) Thanks again, mirabilos. You’re welcome. bye, //mirabilos -- theftf Ich gebs zu, jupp ist cool -- theftf zu Natureshadow beim Fixen von Debian
Re: IFS=:; ${-+:foo:var} skips the first empty element
Thorsten Glaser tg at mirbsd.de writes: michael dixit: (Disclaimer: only somewhat tested, amounting to what $PS2 does.) yay! an excuse not to fix my bad habit. You wonb (And if thereb what's jupp? Oh *wow*. Right. For example, avoid printf(1) on mksh, but use the print builtin (on all Korn shells). ksh93, for small test things, is available though shbot on Freenode IRC. Example: 20:26bshbot k# echo ${.sh.version} 20:26b[[shbot]] Version AJM 93u+ 2012-08-01 If this is about the bug you reported, itb by a check on the shell, as the bug is likely to eventually get fixed, making your code buggy Oh yeah, don't get me wrong, I have no delusions that such a thing will ever be robust in anyway. As is glaringly obvious, there is no version checking in that script - and I don't intend to add any. It was just a thought experiment. My platoon sergeant once told me that if I wanted to understand how my tools work, I should try extending them. That's all that was - you won't find it on github or anything. I just thought you might like to see that the solution on this end was checking if the splitter was at the head and, if so, appending another. I thought a similar tactic might on apply on your end. But I dunno. -mike