----------------------------------------------------

原文:http://unix.stackexchange.com/questions/286336/error-thrown-when-using-su-c-bash-no-job-control-in-this-shell

Job control is a collection of features in the shell and the tty driver which allow the user to manage multiple jobs from a single interactive shell.

A job is a single command or a pipeline. If you run ls, that's a job. If you run ls|more, that's still just one job. If the command you run starts subprocesses of its own, then they will also belong to the same job unless they are intentionally detached.

Without job control, you have the ability to put a job in the background by adding & to the command line. And that's about all the control you have.

With job control, you can additionally:

  1. Suspend a running foreground job with CtrlZ
  2. Resume a suspended job in the foreground with fg
  3. Resume a suspend job in the background with bg
  4. Bring a running background job into the foreground with fg

The shell maintains a list of jobs whcih you can see by running the jobs command. Each one is assigned a job number (distinct from the PIDs of the process(es) that make up the job). You can use the job number, prefixed with %, as an argument to fg or bg to select a job to foreground or background. The %jobnumber notation is also acceptable to the shell's builtin kill command. This can be convenient because the job numbers are assigned starting from 1, so they're shorter than PIDs.

There are also shortcuts %+ for the most recently foregrounded job and %- for the previously foregrounded job, so you can switch back and forth rapidly between two jobs with CtrlZ followed by fg %- (suspend the current one, resume the other one) without having to remember the numbers. Or you can use the beginning of the command itself. If you have suspended an ffmpeg command, resuming it is as easy as fg %ff (assuming no other active jobs start with "ff"). And as one last shortcut, you don't have to type the fg. Just entering %- as a command foregrounds the previous job.

"But why do we need this?" I can hear you asking. "I can just start another shell if I want to run another command." True, there are many ways of multitasking. On a normal day I have login shells running on tty1 through tty10 (yes there are more than 6, you just have to activate them), one of which will be running a screen session with 4 screens in it, another might have an ssh running on it in which there is another screen session running on the remote machine, plus my X session with 3 or 4 xterms. And I still use job control.

If I'm in the middle of vi or less or aptitude or any other interactive thing, and I need to run a couple of other quick commands to decide how to proceed, CtrlZ, run the commands, and fg is natural and quick. (In lots of cases an interactive program has a ! keybinding to run an external command for you; I don't think that's as good because you don't get the benefit of your shell's history, command line editor, and completion system.) I find it sad whenever I see someone launch a secondary xterm/screen/whatever to run one command, look at it for two seconds, and then exit.

Now about this script of yours. In general it does not appear to be competently written. The line in question:

bash -i -c "ssh -D 7070 -N user@my-ssh.example.com > /dev/null"

is confusing. I can't figure out why the ssh command is being passed down to a separate shell instead of just being executed straight from the main script, let alone why someone added -i to it. The -ioption tells the shell to run interactively, which activates job control (among other things). But it isn't actually being used interactively. Whatever the purpose was behind the separate shell and the -i, the warning about job control was a side effect. I'm guessing it was a hack to get around some undesirable feature of ssh. That's the kind of thing that when you do it, you should comment it.

linux shell操作的更多相关文章

  1. Linux shell 操作 postgresql,并设置crontab任务

    Linux shell 操作 postgresql:删除间隔日期的数据-删除指定日期的数据-vacuumdb 清理数据库 -清理日志 -定期执行脚本 *修改pg_hba.conf 设置本地连接无密码, ...

  2. linux shell 操作 mysql命令(不进入mysql操作界面)

    由于需要,需要将一系列mysql的操作制作成.sh文件,只需要shell操作bash命令就可以傻瓜式的完成黑盒任务. #!/bin/bash mysql -uroot -p??? -e "c ...

  3. java代码运行linux shell操作

    1.Java调用shell  Java语言以其跨平台性和简易性而著称,在Java里面的lang包里(java.lang.Runtime)提供了一个允许Java程序与该程序所运行的环境交互的接口,这就是 ...

  4. Linux Shell操作 执行C代码显示当前路径

    在unix系统下一切皆文件,文件夹是文件的一种.设备也会对应到相应的文件类型. 基础知识: . 代表当前路径 ..代表上级目录(父目录) / 在路径的最前边的时候代表树根.在路径中间的时候只不过是路径 ...

  5. Linux Shell 文件描述符 及 stdin stdout stderr 重定向

    Abstract: 1) Linux Shell 命令的标准输入.标准输出.标准错误,及其重定位: 2)Linux Shell 操作自定义文件描述符: 文件描述符是与文件相关联的一些整数,他们保持与已 ...

  6. Linux Shell 笔记

    1.查看进程的环境变量 普通:$cat /proc/1642/environ  换行:$cat /proc/1642/environ | tr '\0' '\n' tr的命令格式是tr SET1 SE ...

  7. Linux Shell数组常用操作详解

    Linux Shell数组常用操作详解 1数组定义: declare -a 数组名 数组名=(元素1 元素2 元素3 ) declare -a array array=( ) 数组用小括号括起,数组元 ...

  8. linux shell 字符串操作(长度,查找,替换)详解

    linux shell 字符串操作(长度,查找,替换)详解 在做shell批处理程序时候,经常会涉及到字符串相关操作.有很多命令语句,如:awk,sed都可以做字符串各种操作. 其实shell内置一系 ...

  9. linux下的shell操作mysql

    (1)MySQL的启动 重启了一次服务器后,使用> mysql -u root -p登陆是出现下面的错误: ERROR 2002 (HY000): Can't connect to local ...

随机推荐

  1. python安装mysql-connector出错

    windows 7环境 1.进入命令行执行以下命令: C:\Users\Administrator>pip install mysql-connector 注:安装下载较慢,直接失败,改用VPN ...

  2. nginx目录结构和配置文件

    nginx软件功能模块说明 Nginx软件之所以强大,是因为它具有众多的功能模块,下面列出了企业常用的重要模块. (1) Nginx核心功能模块(Core functionality)nginx核心功 ...

  3. Python中如何将数据存储为json格式的文件(续)

    将上一篇中的例子,修改一下,将两个程序合二为一,如果存储了用户喜欢的水果就显示它,否则提示用户输入他喜欢的水果并将其存储到文件中. favorite.py import json filename = ...

  4. wordpress配置SMTP服务发送邮件(qq邮箱)

    wordpress有一个注册功能,填了用户名和邮箱后,会收到一封邮件,邮件里有一个链接,点击该链接可以获得密码和修改密码.但是,最开始,你会发现,等半天都没有收到邮件,再等到猴年马月也不会收到. 但是 ...

  5. Android开发——IntentFilter的匹配规则

    1.  IntentFilter中的过滤信息 启动Activity分为显式调用和隐式调用,前者没什么好讲的,后者需要Intent能够匹配目标组件的IntentFilter中所设置的过滤信息.包括act ...

  6. angular中几种加载css的方法

    1.Style URLs in Metadata We can load styles from external CSS files by adding a styleUrls attribute ...

  7. 【01】CSS规范

    [01]CSS规范 []https://drafts.csswg.org/indexes/(下图)   https://www.w3.org/TR/2011/REC-CSS2-20110607/   ...

  8. PTA 10-排序5 PAT Judge (25分)

    题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/677 5-15 PAT Judge   (25分) The ranklist of PA ...

  9. out.print和out.write

    这是一个JSP页面: <%@ page language="java" import="java.util.*"  %> <%@ page p ...

  10. Generation I

    Generation I Oak is given N empty and non-repeatable sets which are numbered from 1 to N. Now Oak is ...