git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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.

Previous: Brandon CaseyNext: Brandon Casey
Message 3 of 7 in “git-rebase--interactive.sh: LF terminate line sent to cut”
  1. git-rebase--interactive.sh: LF terminate line sent to cutChris Johnsen, Sep 17, 2010
  2. Brandon CaseySep 17, 2010
  3. Junio C HamanoSep 17, 2010
  4. Brandon CaseySep 17, 2010
  5. git-rebase--interactive.sh: replace cut with ${v%% *}Chris Johnsen, Sep 17, 2010
  6. Junio C HamanoSep 17, 2010
  7. Chris JohnsenSep 18, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.