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

原文: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. Git学习——查看修改记录

    查看修改结果 修改之前commit的文件,输入下面的而命令,可以查看文件的改动,输入下面命令.还可以采用git diff命令来看看具体修改了什么. 如果确认无误,添加add和提交commit文件. g ...

  2. a标签中javascript和void

    <body> <a href="javascript:;">点了无反应</a> <a href="javascript:void ...

  3. cache控制器取值从TCM/CACHE/FLASH

    cache 控制器顶层有4组接口,分别为输入I/D bus ,输出TCM bus /Cache bus /direct flash bus (走cache ID bus matrix) flash 控 ...

  4. python 学习第二周总复习

    目录 数据类型内置方法 数字类型内置方法 整型 浮点型 字符串类型内置方法 列表类型内置方法 元祖类型内置方法 字典类型内置方法 集合类型内置方法 布尔类型 数据类型总结 拷贝 浅拷贝 深拷贝 053 ...

  5. XML,面向对象基础

    什么是XML XML与JSON的对比 XML文档格式 使用XML模块解析 一,什么是XML ''' XML 全称可扩展标记语言 <tag></tag> 双标签 <tag/ ...

  6. The US in understimating Huawei, says founder Ren zhengfei

    Huawei Founder Ren Zhengfei has downplayed the impact of the US executive order that cripple Huawei' ...

  7. Hive 启动报错 URI

    Exception in thread "main"java.lang.RuntimeException: java.lang.IllegalArgumentException:j ...

  8. luogu3629 [APIO2010]巡逻

    创造一个环出来,可以让环上的边都只访问一次. 对于 \(k=1\),答案就是树的直径两边连起来. 倘若 \(k=2\),那就先按照 \(k=1\) 的求一遍,然后我们发现,如果第二条加的边构成的环和第 ...

  9. 学习笔记7——wp版本更新需要注意的问题

    平时开发时应该避免修改wp的核心代码, 因为在升级wp版本时,核心代码都会被覆盖, wp升级时只有wp-content文件夹不会被覆盖.

  10. Lenovo笔记本电脑进入BIOS的方法

    使用NOVO键开机进入BIOS的操作方法 适用范围:2012年后发布的部分笔记本产品,含:IdeaPad全系列.Lenovo G系列部分IdeaPad U或S系列,YOGA/FLEX全系列产品Leno ...