bug-bash
[Top][All Lists]
Advanced

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

Re: New Feature Request


From: Saint Michael
Subject: Re: New Feature Request
Date: Mon, 4 Jan 2021 08:26:59 -0500

In this case, how do I quickly increase the number stored in "foo"?
the file has 10000 as content, and I have a new value to add to it quickly.
Is there an atomic way to read,add, write a value to "foo"?


On Mon, Jan 4, 2021 at 8:15 AM Greg Wooledge <wooledg@eeg.ccf.org> wrote:

> On Fri, Jan 01, 2021 at 10:02:26PM +0100, Ángel wrote:
> > Yes. In fact, you can already do that using an interface exactly
> > identical to file operations:
> >
> > # Store a string in shared memory with key 'foo'
> > echo "Hello world" > foo
> >
> > # Read value of key foo
> > var="$(<foo)"
> >
> >
> > You only need to use that on a tmpfs filesystem, and it will be stored
> > in memory. Or, if you wanted to persist your shared memory between
> > reboots, or between machines, you could place them instead on a local
> > or networked filesystem.
>
> It should be noted that $(<foo) still forks a process.  If you want the
> script to be faster, you'll need some other way to read the data from
> the file -- perhaps using the read -r -d '' command, or the mapfile
> command.
>
> Other forms of IPC that are viable in scripts include using a FIFO that's
> held open by both parent and child, or launching the child as a coprocess.
>
>


reply via email to

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