Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | package Psh::Builtins::Bg; |
2 | ||
3 | require Psh::Util; | |
4 | require Psh::Joblist; | |
5 | ||
6 | =item * C<bg [%JOB|COMMAND]> | |
7 | ||
8 | Put a job into the background. If JOB is omitted, uses the | |
9 | highest-numbered stopped job, if any. | |
10 | ||
11 | If you specify a command instead of a job id it will execute | |
12 | the command in the background. You can use this if you do not | |
13 | want to type "command &". | |
14 | ||
15 | =cut | |
16 | ||
17 | sub bi_bg | |
18 | { | |
19 | my $arg = shift; | |
20 | ||
21 | if( ! Psh::OS::has_job_control()) { | |
22 | Psh::Util::print_error_i18n('no_jobcontrol'); | |
23 | return (0,undef); | |
24 | } | |
25 | ||
26 | if (!defined($arg) || $arg eq '') { | |
27 | ($arg)= Psh::Joblist::find_job(); | |
28 | } else { | |
29 | if( $arg !~ /^\%/) { | |
30 | return Psh::evl($arg.' &'); | |
31 | } | |
32 | $arg =~ s/\%//; | |
33 | ||
34 | if ( $arg !~ /^\d+$/) { | |
35 | ($arg)= Psh::Joblist::find_last_with_name($arg,0); | |
36 | } | |
37 | $arg-- if defined($arg); | |
38 | } | |
39 | return (0,undef) unless defined($arg); | |
40 | ||
41 | Psh::OS::restart_job(0, $arg); | |
42 | ||
43 | return (1,undef); | |
44 | } | |
45 | ||
46 | 1; |