patches and low-level development discussion
 help / color / mirror / code / Atom feed
From: Alyssa Ross <alyssa.ross@unikie.com>
To: Henri Rosten <henri.rosten@unikie.com>
Cc: devel@spectrum-os.org
Subject: Re: [PATCH] Remove bashisms from spectrum shell scripts
Date: Wed, 9 Nov 2022 12:32:10 +0000	[thread overview]
Message-ID: <20221109123210.vxexqshbv7vvrhgg@x220> (raw)
In-Reply-To: <20221108150512.GA833412@buamix>

[-- Attachment #1: Type: text/plain, Size: 1132 bytes --]

> > > @@ -38,7 +39,7 @@ scriptsDir="$(dirname "$0")"
> > >  out="$1"
> > >  shift
> > >
> > > -nl=$'\n'
> > > +nl='\n'
> > >  table="label: gpt"
> > >
> > >  # Keep 1MiB free at the start, and 1MiB free at the end.
> > > @@ -51,9 +52,7 @@ done
> > >
> > >  rm -f "$out"
> > >  truncate -s "$gptBytes" "$out"
> > > -sfdisk "$out" <<EOF
> > > -$table
> > > -EOF
> > > +printf "$table" | sfdisk "$out"
> >
> > The heredoc previously used here should be POSIX:
> >
> >   https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_07_04
> >
> > Does it not work in dash?
> >
>
> Heredoc works in dash too, but I couldn't find out how to expand the
> newlines in variable inside heredoc so that it would work in dash.
> Therefore I simply removed the heredoc and used printf instead.

I think the problem there is this one:

  https://www.shellcheck.net/wiki/SC3003 -- In POSIX sh, $'..' is undefined.

So I think we could fix it without introducing an extra printf process,
by changing how we define `nl` to use a literal newline.

The following test script worked for me in dash:

nl='
'
cat <<EOF
foo${nl}bar
EOF

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2022-11-09 12:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-08 10:05 Henri Rosten
2022-11-08 13:27 ` Alyssa Ross
2022-11-08 15:05   ` Henri Rosten
2022-11-09 12:32     ` Alyssa Ross [this message]
2022-11-09 12:59       ` Henri Rosten

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221109123210.vxexqshbv7vvrhgg@x220 \
    --to=alyssa.ross@unikie.com \
    --cc=devel@spectrum-os.org \
    --cc=henri.rosten@unikie.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).