Re: [PATCH] git-rebase--interactive.sh: LF terminate line sent to cut
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 17, 2010, 18:38 UTC
- Message-ID
- <7vsk182p2q.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <XhMLJaG8mUbh4rzLnU3IrGDXbMd9-p7UFO6kn9Uke7n_H4NNOG6glg@cipher.nrlssc.navy.mil>
Brandon Casey <brandon.casey.ctr@nrlssc.navy.mil> writes:
Show 6 quoted lines
> Or we could write it like:
>
> sha1=${rest%% *}
>
> which I wish I had changed it to in the first place when I made some
> recent modifications.Agreed; the less use of 'cut' we see, the better ;-)
As to portability guideline in our shell script:
${param#word} ${param##word} ${param%word} ${param%%word}are permissible POSIX constructs (together with more traditional -/=/?/+), and their use is encouraged over 'cut', 'expr', etc. [*1*]
${param:ofs} ${param:ofs:len} ${param/pattern/string}are bashisms we avoid (unless of course in the bash completion script).
We do not seem to use ${#param}, not because it is forbidden, but I think because it is not very useful without ${param:ofs:len}.
[Footnote]
*1* In 2005 back when I took over the git maintenance, I used to be a lot more conservative/traditionalist and as a result, you may see overused "expr" in contrib/examples/ and "git log -p -- '*.sh'" output. But we have been eradicating them a bit by bit for the past few years.