“fg %N”命令的作用是什么?

cod*_*nza 1 command-line

我知道这fg %N意味着“去执行任务N

我不明白这个命令或如何使用它。我试图在终端中查看此命令的手动输入,但这不起作用:

$ man fg
No manual entry for fg.
Run Code Online (Sandbox Code Playgroud)

ste*_*ver 9

第二个:fg是 bash shell 内置命令,因此您需要参考bash. 特别是,该部分JOB CONTROL

   Simply naming a job can be used to bring it into the foreground: %1  is
   a  synonym  for  ``fg %1'', bringing job 1 from the background into the
   foreground.  Similarly, ``%1 &''  resumes  job  1  in  the  background,
   equivalent to ``bg %1''.
Run Code Online (Sandbox Code Playgroud)

或者,您可以使用 shell 的交互help系统:

$ help fg
fg: fg [job_spec]
    Move job to the foreground.

    Place the job identified by JOB_SPEC in the foreground, making it the
    current job.  If JOB_SPEC is not present, the shell's notion of the
    current job is used.

    Exit Status:
    Status of command placed in foreground, or failure if an error occurs.
Run Code Online (Sandbox Code Playgroud)

现在是第一部分。您所说的实际命令实际上并没有重定向stdoutstderr:它将标准输出重定向到一个名为 2 的文件,然后将整个命令放入 shell 的后台。因此

$ man 1>2&
[1] 4662
Run Code Online (Sandbox Code Playgroud)

运行man在后台(如作业[1],进程ID 4662) -如果在当前目录中查找你可能会发现一个名为2与内容

 What manual page do you want?
Run Code Online (Sandbox Code Playgroud)

您应该使用的命令是 1>&2

  • &2文件描述符#2
  • 2&: 文件 2,命令在后台运行

欲了解更多信息,请参阅REDIRECTIONman bash


Joh*_*024 8

  1. fg 是一个 bash 内置命令:

    $ type fg
    fg is a shell builtin
    
    Run Code Online (Sandbox Code Playgroud)

    要获取有关单个 bash 命令的信息,请使用help

    $ help fg
    fg: fg [job_spec]
        Move job to the foreground.
    
        Place the job identified by JOB_SPEC in the foreground, making it the
        current job.  If JOB_SPEC is not present, the shell's notion of the
        current job is used.
    
        Exit Status:
        Status of command placed in foreground, or failure if an error occurs.
    
    Run Code Online (Sandbox Code Playgroud)
  2. 正如问题的第一个版本中提到的,1>&2redirection 的一个例子。要阅读有关重定向的信息,请运行man bash并转到标题为REDIRECTION.