mainThe GNU Bourne-Again SHell - Support: sr #108616, "jobs" shows 'less...


sr #108616: "jobs" shows 'less "$@"' rather than actual argument with function

Submitter:  None
Submitted:  Tue 15 Jul 2014 07:13:58 PM UTC
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  Wont Do
Privacy:  Public Assigned to:  None
Originator Email:  -email is unavailable- Open/Closed:  Open
Operating System:  GNU/Linux
* Mandatory Fields

Add a New Comment Rich Markup

Fri 13 Nov 2015 05:57:46 PM UTC, comment #1: 

The question is what the command line looks like when the child is forked, and what is saved in the jobs list.

In the two cases involving aliases, the alias has been replaced by `sleep' before word expansion takes place (or a child is forked) because the parser performs alias expansion.

In the case of the shell function invoking a foreground job (sleep "$@"), you are correct: the command line that is stored in the job structure is the command before word expansion is performed.  That is how bash has always done things (and when I say always, I mean back to the pre-bash-1.0 days 27 years ago), and there isn't a good reason to change it now.

In the final case, the entire shell function is run in the background, so running the `sleep "$@"' is performed in the child.  In the parent, the command line is the call to sleep_function, and that is what shows up in the jobs list.

FWIW, ksh93 doesn't list the command at all, mksh and dash behave like bash, and zsh displays the expanded command.

Chet Ramey <chet>
Group administrator
Tue 15 Jul 2014 07:13:58 PM UTC, original submission:  

I have an abbreviation "le" for the "less" command (just to save
typing). I originally I had this as a shell function, but I found that
stopped jobs showed up in the "jobs" output as 'less "$@"' rather than
showing the actual argument. Changing it to an alias avoids that problem
(but is obviously less flexible).

A demonstration (for simplicity I'm using sleep rather than less):

$ uname -a
Linux bomb20 3.5.0-51-generic #76-Ubuntu SMP Thu May 15 21:19:10 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
$ alias sleep_alias=sleep
$ sleep_function() { sleep "$@" ; }
$ sleep_alias 100
[1]+  Stopped                 sleep 100
$ sleep_function 200
[2]+  Stopped                 sleep "$@"
$ bg
[2]+ sleep "$@" &
$ sleep_alias 300 &
[3] 20825
$ sleep_function 400 &
[4] 20826
$ jobs
[1]+  Stopped                 sleep 100
[2]   Running                 sleep "$@" &
[3]   Running                 sleep 300 &
[4]-  Running                 sleep_function 400 &

The problem is that the "jobs" command shows 'sleep "$@" &' for job 2,
where it should show 'sleep 200 &'. It's interesting that this problem
occurs when a job is stopped with Control-Z but not when it's launched
in the background with "&".



(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

Attached Files
file #31725:  bash-bug.txt added by None (670B - text/plain - Demonstration of bug (didn't show up in original submission))


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by chet (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.


    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-11-13 chet StatusNone Wont Do
    2014-07-15 None Attached File- Added bash-bug.txt, #31725

    Back to the top

    Powered by Savane 3.12.
    Corresponding source code