help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: strange redirection error


From: Kerin Millar
Subject: Re: strange redirection error
Date: Wed, 15 Sep 2021 21:33:28 +0100

On Mon, 13 Sep 2021 17:24:36 +0200
Christoph Anton Mitterer <calestyo@scientia.net> wrote:

> Hey Greg.
> 
> On Sun, 2021-09-12 at 20:13 -0400, Greg Wooledge wrote:
> > I don't know what you mean by portable, exactly.  This is help-bash,
> > though, so we can initially assume that you are using bash.
> 
> Well I meant using only POSIX compatible features, but also working in
> bash.
> It works in the other shells I've tested, but not in bash (at least not
> without that exec) so I figured it would be appropriate to ask the bash
> folks why it doesn't work there ;-)
> 
> 
> > The way you do this in bash is quite simple:
> > 
> > #!/bin/bash
> > output=$(cmd1 | cmd2)
> > exitstatus1=${PIPESTATUS[0]}
> > exitstatus2=${PIPESTATUS[1]}
> > 
> > Easy enough, right?
> 
> Sure, but that it would work in bash *only* and no longer in the
> others.
> 
> 
> > The simplest way to do that is to introduce a temp
> > file or two.
> 
> That's not an option, a) in my case, where keys are read, one wouldn't
> want to write them unnecessarily,... b) the whole system might be still
> read only (this code will be run from within an initramfs).

Not to dissuade you from finding concrete answers to the questions that you 
originally posed, but it is an option and I would caution against dismissing it 
out of hand. As concerns the first objection, the nature of Greg's example is 
such that only the exit status values would be written to the filesystem. As 
concerns the second objection, the type of the initial root filesystem will be 
rootfs, which is a specialised instance of either ramfs or tmpfs. Regardless, 
it is always writeable. Were that not the case, the call to populate_rootfs() 
in init/initramfs.c would fail. As such, the only way for this filesystem to be 
rendered read-only would be for you to first execute `mount -o remount,ro /` in 
your /init script, or to execute some other program that proceeds to remount in 
that exact fashion.

-- 
Kerin Millar



reply via email to

[Prev in Thread] Current Thread [Next in Thread]