`jobs` shows output even when nothing has been started in the background

2023-06-14 Thread Ajeet D'Souza
*Configuration Information [Automatically generated, do not change]:*
Machine: aarch64
OS: darwin22.1.0
Compiler: clang
Compilation CFLAGS: -DSSH_SOURCE_BASHRC
uname output: Darwin ip-192-168-0-101.ap-south-1.compute.internal 22.3.0
Darwin Kernel Version 22.3.0: Thu Jan  5 20:48:54 PST 2023;
root:xnu-8792.81.2~2/RELEASE_ARM64_T6000 arm64
Machine Type: aarch64-apple-darwin22.1.0

Bash Version: 5.2
Patch Level: 15
Release Status: release

*Description:*
I apologize if this is not a bug, but I couldn't find any documentation
around this behaviour.

In Bash, this does not produce any output:
/bin/echo; jobs -l

But if you run it in a subshell, it does:
(/bin/echo; jobs -l) # output: [1]  42135 Done/bin/echo

Similar problem if you put this into $PROMPT_COMMAND, although it does not
run in a subshell AFAIK:
PROMPT_COMMAND='/bin/echo; jobs -l' # output on every prompt: [1]  42135
Done/bin/echo

This happens only for external processes, if you were to use the builtin
echo, it would not show any background process. However, in all 3 cases,
the applications have been started normally in the foreground, but somehow
the behaviour is different. I have two questions here:

   - Is this a bug, or is this expected behavior?
   - Is there a way I can start an external process in $PROMPT_COMMAND without
   it showing up in jobs?

Context: I'm the maintainer of zoxide
 (a Bash plugin), and this behavior
is causing it to clash with the jobs indicator of starship
 (a popular prompt). This issue
should provide more information:
https://github.com/starship/starship/issues/5159

*Repeat-By:*
This command ideally should not have any output:
(/bin/echo; jobs -l)


Re: New array_expand_once option

2023-06-14 Thread Chet Ramey

On 6/13/23 7:12 PM, alex xmb ratchev wrote:


any word s about [[ -v
.. ?



Using the assignments above,

[[ -v a["$subscript"] ]]

is already an arithmetic expansion error in bash-5.2, but not in bash-5.1.
Inhibiting double expansions like those for shell compound commands was one
of the changes between bash-5.1 and bash-5.2.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/




Re: `jobs` shows output even when nothing has been started in the background

2023-06-14 Thread Chet Ramey

On 6/14/23 4:47 AM, Ajeet D'Souza wrote:


Bash Version: 5.2
Patch Level: 15
Release Status: release

*Description:*
I apologize if this is not a bug, but I couldn't find any documentation
around this behaviour.

In Bash, this does not produce any output:
/bin/echo; jobs -l

But if you run it in a subshell, it does:
(/bin/echo; jobs -l) # output: [1]  42135 Done/bin/echo

Similar problem if you put this into $PROMPT_COMMAND, although it does not
run in a subshell AFAIK:
PROMPT_COMMAND='/bin/echo; jobs -l' # output on every prompt: [1]  42135
Done/bin/echo

This happens only for external processes, if you were to use the builtin
echo, it would not show any background process. 


Thanks for the report. I changed this back in late September, 2022 after
a bug-bash discussion:

https://lists.gnu.org/archive/html/bug-bash/2022-09/msg00067.html

The original report was

https://lists.gnu.org/archive/html/bug-bash/2022-07/msg00117.html

The original (through bash-5.2) behavior was due to the subshell not
notifying the user about the status of the completed foreground job,
even though not running it in a subshell ignored foreground jobs. The
fix was to remove terminated foreground jobs the shell would never notify
the user about (foreground jobs not killed by a signal) from the jobs list.

Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/




Re: New array_expand_once option

2023-06-14 Thread alex xmb ratchev
On Wed, Jun 14, 2023, 15:34 Chet Ramey  wrote:

> On 6/13/23 7:12 PM, alex xmb ratchev wrote:
>
> > any word s about [[ -v
> > .. ?
> >
>
> Using the assignments above,
>
> [[ -v a["$subscript"] ]]
>
> is already an arithmetic expansion error in bash-5.2, but not in bash-5.1.
>

hello there ..

i dont get much
it d be an arith err if array wasnt -A
.. ?

so i shopt -s array_expand_once
and [[ -v foo["$var"] ]]
.. is the right way ? ( for the change , the future )

Inhibiting double expansions like those for shell compound commands was one
> of the changes between bash-5.1 and bash-5.2.
>
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>  ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/
>
>


Re: `jobs` shows output even when nothing has been started in the background

2023-06-14 Thread Ajeet D'Souza
Hey Chet,

Thanks for the quick reply. I have some follow-up questions:

   - Is there an elegant way I can start an external process without it
   showing up under jobs, even on affected versions? My current best idea
   is: (_="$(/bin/echo)"; jobs -l)
   - Is there an elegant way I can get the correct number of jobs, even on
   affected versions? My current best idea is to run jobs once before doing
   the count: (jobs &> /dev/null; jobs | wc -l)

I'm trying to keep the behaviour consistent across all versions of Bash.

Thanks,
Ajeet

On Wed, Jun 14, 2023 at 8:17 PM Chet Ramey  wrote:

> On 6/14/23 4:47 AM, Ajeet D'Souza wrote:
>
> > Bash Version: 5.2
> > Patch Level: 15
> > Release Status: release
> >
> > *Description:*
> > I apologize if this is not a bug, but I couldn't find any documentation
> > around this behaviour.
> >
> > In Bash, this does not produce any output:
> > /bin/echo; jobs -l
> >
> > But if you run it in a subshell, it does:
> > (/bin/echo; jobs -l) # output: [1]  42135 Done
> /bin/echo
> >
> > Similar problem if you put this into $PROMPT_COMMAND, although it does
> not
> > run in a subshell AFAIK:
> > PROMPT_COMMAND='/bin/echo; jobs -l' # output on every prompt: [1]  42135
> > Done/bin/echo
> >
> > This happens only for external processes, if you were to use the builtin
> > echo, it would not show any background process.
>
> Thanks for the report. I changed this back in late September, 2022 after
> a bug-bash discussion:
>
> https://lists.gnu.org/archive/html/bug-bash/2022-09/msg00067.html
>
> The original report was
>
> https://lists.gnu.org/archive/html/bug-bash/2022-07/msg00117.html
>
> The original (through bash-5.2) behavior was due to the subshell not
> notifying the user about the status of the completed foreground job,
> even though not running it in a subshell ignored foreground jobs. The
> fix was to remove terminated foreground jobs the shell would never notify
> the user about (foreground jobs not killed by a signal) from the jobs list.
>
> Chet
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>  ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/
>
>