文章目录

  • sh/bash/shell_bash参考文档
    • references
    • conclusion
    • What Is a Shell?
    • 查看本机的可用shell程序
    • sh
      • sh on POSIX Systems
    • Bash
    • Which One to Use?
    • bash的常用功能
      • 引号(单引号/双引号/backquote)
        • 反引号(Command Substitution)
      • 元字符
        • 转义
      • 通配
  • bash_命令行编辑快捷键&技巧/shell job任务管理/job vs process
    • reference
    • 编辑快捷键Moving the Cursor
      • 光标跳转
      • 文本修改Capitalizing Characters
    • 进程管理快捷键
      • 杀死当前进程(软杀)
      • 挂起当前进程(暂停执行)
      • 关闭/离开当前shell
      • job vs process
    • Working With Your Command History
    • bash参考手册

sh/bash/shell_bash参考文档

references

  • What’s the Difference Between sh and Bash? | Baeldung on Linux
  • Bash Reference Manual (gnu.org)

conclusion

  • sh 是一类命令行编程语言(满足POSIX标准)
  • bash 是sh的一种具体的实现程序
    • sh有其他的实现
    • 个人感觉有点想js和ecma之间的关系

What Is a Shell?

  • A shell is a computer program that takes commands, interprets them, and passes them to the operating system to process.
  • So, it’s an interface between the user and the operating system, through which a user can interact with the computer.
  • To interact with the shell, we need a terminal emulator such as gnome-terminal, konsole, or st.
  • Most Linux-based operating systems come with at least one shell program. The shell program will probably be Dash, Bash, or both.

user->terminal->shell->system

查看本机的可用shell程序

  • cat /etc/shells

sh

  • sh also known as Bourne Shell, is a command programming language for UNIX-like systems, defined by the POSIX standards .
  • sh can take input from either a keyboard or a file (commonly called a script file).
  • On most Linux systems, it’s implemented by programs like the original Bourne Shell , dash , and ksh.

sh on POSIX Systems

POSIX is a family of standards defined by IEEE for vendors to make operating systems compatible. Thus, it helps us develop cross-platform software for multiple operating systems by following a set of guidelines. *sh *conforms to these standards.

  • On most Linux systems, sh is a symlink to the actual implementation of Bourne Shell .
  • We can verify it through the following command:

某些发行版可能需要手动安装 file 命令

  • file: Determine type of FILEs.
    sudo apt install file
$ file -h /bin/sh/bin/sh: symbolic link to dash
  • As we can see, the /bin/sh is symbolically linked to dash, which is a POSIX compliant shell used by Debian-based distributions. In shell scripts, we can put the #!/bin/sh, as the first line, which in turn will be executed by dash

Bash

  • Like sh , Bash (Bourne Again Shell) is a command language processor and a shell. It’s the default login shell on most Linux distributions.

  • Bash is a superset of sh, which means that Bash supports features of sh and provides more extensions on top of that.

    • Though, most of the commands work similarly as in sh .
  • Since the release of Bash, it’s been the de facto shell for Linux operating systems.

Which One to Use?

  • Both shells are useful, and we can leverage them in different situations. For instance, we can use sh if we want our script to be compatible across multiple systems. On the other hand, we might choose Bash because it provides a fluid syntax and more compelling features.
  • Nonetheless, we can use Bash and run it in pure POSIX mode if we are paranoid about portability and compatibility. Aside from that, if we write a sh script, it will most likely run on Bash without modification because Bash is backward-compatible with sh .

bash的常用功能

  • 使用 man bash可以看到较为完整的bash介绍
  • 使用在线文档,方便浏览Bash Reference Manual (gnu.org)

引号(单引号/双引号/backquote)

  • Quoting (Bash Reference Manual) (gnu.org)

反引号(Command Substitution)

Command substitution allows the output of a command to replace the command itself. Command substitution occurs when a command is enclosed as follows:

$(command)

or

`command`
  • Bash performs the expansion by executing command in a subshell environment and replacing the command substitution with the standard output of the command, with any trailing newlines deleted. Embedded newlines are not deleted, but they may be removed during word splitting. The command substitution $(cat<span> </span><var>file</var>) can be replaced by the equivalent but faster $(<<span> </span><var>file</var>).

元字符

  • $
  • #
  • (space)

转义

  • 对元字符转移,可以阻止shell对字符的特殊解释(当成普通字符来看待)

通配

       Pattern MatchingAny  character  that appears in a pattern, other than the special pattern charac‐ters described below, matches itself.  The NUL character may not occur in a  pat‐tern.   A  backslash  escapes  the following character; the escaping backslash isdiscarded when matching.  The special pattern characters must be quoted  if  theyare to be matched literally.The special pattern characters have the following meanings:*      Matches  any  string, including the null string.  When the globstarshell option is enabled, and * is used in a pathname expansion con‐text, two adjacent *s used as a single pattern will match all filesand zero or more directories and subdirectories.  If followed by  a/, two adjacent *s will match only directories and subdirectories.?      Matches any single character.[...]  Matches  any  one of the enclosed characters.  A pair of charactersseparated by a hyphen denotes a  range  expression;  any  characterthat  falls between those two characters, inclusive, using the cur‐rent locale's collating sequence and character set, is matched.  Ifthe first character following the [ is a !  or a ^ then any charac‐ter not enclosed is matched.  The sorting order  of  characters  inrange  expressions is determined by the current locale and the val‐ues of the LC_COLLATE or LC_ALL shell variables, if set.  To obtainthe traditional interpretation of range expressions, where [a-d] isequivalent to [abcd], set value of the LC_ALL shell variable to  C,or  enable the globasciiranges shell option.  A - may be matched byincluding it as the first or last character in the set.  A ] may bematched by including it as the first character in the set.Within [ and ], character classes can be specified using the syntax[:class:], where class is one of the following classes  defined  inthe POSIX standard:alnum  alpha  ascii blank cntrl digit graph lower print punct spaceupper word xdigitA character class matches any character belonging  to  that  class.The word character class matches letters, digits, and the character_.Within [ and ], an equivalence class can  be  specified  using  thesyntax  [=c=], which matches all characters with the same collationweight (as defined by the current locale) as the character c.Within [ and ], the syntax [.symbol.] matches the collating  symbolsymbol.If  the extglob shell option is enabled using the shopt builtin, several extendedpattern matching operators are recognized.  In the following description, a  pat‐tern-list is a list of one or more patterns separated by a |.  Composite patternsmay be formed using one or more of the following sub-patterns:?(pattern-list)Matches zero or one occurrence of the given patterns*(pattern-list)Matches zero or more occurrences of the given patterns+(pattern-list)Matches one or more occurrences of the given patterns@(pattern-list)Matches one of the given patterns!(pattern-list)Matches anything except one of the given patternsComplicated extended pattern matching against long strings  is  slow,  especiallywhen  the patterns contain alternations and the strings contain multiple matches.Using separate matches against shorter strings, or using arrays  of  strings  in‐stead of a single long string, may be faster.

bash_命令行编辑快捷键&技巧/shell job任务管理/job vs process

reference

  • The Best Keyboard Shortcuts for Bash (aka the Linux and macOS Terminal) (howtogeek.com)

    • bash中的快捷键主要有Ctrl/Alt连个键打头
    • 同样的快捷键在不同上下文中,可能表现出不同的功能!
    • contents
    • Working With Processes
    • Controlling the Screen
    • Moving the Cursor
    • Deleting Text
    • Fixing Typos
    • Cutting and Pasting
    • Capitalizing Characters
    • Tab Completion
    • Working With Your Command History
    • emacs vs. vi Keyboard Shortcuts
  • bash(1) — Linux manual page

NAME |

SYNOPSIS |

COPYRIGHT | DESCRIPTION | OPTIONS | ARGUMENTS | INVOCATION | DEFINITIONS | RESERVED WORDS |

SHELL GRAMMAR | COMMENTS | QUOTING | PARAMETERS | EXPANSION | REDIRECTION | ALIASES | FUNCTIONS | ARITHMETIC EVALUATION | CONDITIONAL EXPRESSIONS | SIMPLE COMMAND EXPANSION | COMMAND EXECUTION | COMMAND EXECUTION ENVIRONMENT | ENVIRONMENT | EXIT STATUS | SIGNALS |

JOB CONTROL | PROMPTING | READLINE | HISTORY | HISTORY EXPANSION | SHELL BUILTIN COMMANDS | SHELL COMPATIBILITY MODE | RESTRICTED SHELL | SEE ALSO | FILES | AUTHORS | BUG REPORTS | BUGS | COLOPHON

编辑快捷键Moving the Cursor

Use the following shortcuts to quickly move the cursor around the current line while typing a command.

光标跳转

  • Ctrl+A or Home: Go to the beginning of the line.
  • Ctrl+E or End: Go to the end of the line.
  • Alt+B: Go left (back) one word.
    • Ctrl+B: Go left (back) one character.
  • Alt+F: Go right (forward) one word.
    • Ctrl+F: Go right (forward) one character.
  • Ctrl+XX: Move between the beginning of the line and the current position of the cursor.
    • This allows you to press Ctrl+XX to return to the start of the line, change something, and then press Ctrl+XX to go back to your original cursor position.
    • To use this shortcut, hold the Ctrl key and tap the X key twice.

文本修改Capitalizing Characters

The bash shell can quickly convert characters to upper or lower case:

  • Alt+U: Capitalize every character from the cursor to the end of the current word, converting the characters to upper case.
  • Alt+L: Uncapitalize every character from the cursor to the end of the current word, converting the characters to lower case.
  • Alt+C: Capitalize the character under the cursor. Your cursor will move to the end of the current word.
    • 可以用于将行内单词首字母大写化

进程管理快捷键

杀死当前进程(软杀)

  • Ctrl+C: Interrupt (kill) the current foreground process running in in the terminal.

    • This sends the SIGINT signal to the process, which is technically just a request—most processes will honor it, but some may ignore it.

挂起当前进程(暂停执行)

  • Ctrl+Z: Suspend the current foreground process running in bash. This sends the SIGTSTP signal to the process. To return the process to the foreground later, use the fg process_name command.

关闭/离开当前shell

  • 注意,只有在全新的一行输入Ctrl+D才是关闭shell

    Ctrl+D在不同上下文有不同的功能含义

    • 在zsh中,出现在若干字符后,键入Ctrl+D表示要求zsh,提供补全建议
    • 在光标处于某个字符下,ctrl+D表示删除该字符
  • Ctrl+D: Close the bash shell. This sends an EOF (End-of-file) marker to bash, and bash exits when it receives this marker. This is similar to running the exit command.

job vs process

  • JOB CONTROL
      Job control refers to the ability to selectively stop (suspend)the execution of processes and continue (resume) their executionat a later point.  A user typically employs this facility via aninteractive interface supplied jointly by the operating systemkernel's terminal driver and bash.The shell associates a job with each pipeline.  It keeps a tableof currently executing jobs, which may be listed with the jobscommand.  When bash starts a job asynchronously (in thebackground), it prints a line that looks like:[1] 25647indicating that this job is job number 1 and that the process IDof the last process in the pipeline associated with this job is25647. All of the processes in a single pipeline are members of the same job.  Bash uses the job abstraction as the basis for job control.
  • ┌─[cxxu@CxxuWin11] - [~] - [2022-04-20 08:44:08]
    └─[0] <> jobs
    [1]  - 9315 suspended (tty output)  man column |9316 suspended (tty output)  less
    [2]  + 9361 suspended (tty output)  man ls |9362 suspended (tty output)  less
    ┌─[cxxu@CxxuWin11] - [~] - [2022-04-20 08:44:26]
    └─[0] <> fg %2
    [2]  - 9361 continued  man ls |9362 continued  less# cxxu @ CxxuWin11 in ~ [8:51:47]
    $ man ls|grep 'r'|less[1]  + 9760 done       man ls |9761 done       grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox} 'r' |9763 suspended  less
    
    • 根据文档 All of the processes in a single pipeline are members of the same job.可知,一个job可以包括管道符链接起来的多个进程,这些进程同属于一个job号

Working With Your Command History

RELATED: *How to Use Your Bash History in the Linux or macOS Terminal*

You can quickly scroll through your recent commands, which are stored in your user account’s bash history file:

  • Ctrl+P or Up Arrow: Go to the previous command in the command history. Press the shortcut multiple times to walk back through the history.
  • Ctrl+N or Down Arrow: Go to the next command in the command history. Press the shortcut multiple times to walk forward through the history.
  • Alt+R: Revert any changes to a command you’ve pulled from your history if you’ve edited it.

Bash also has a special “recall” mode you can use to search for commands you’ve previously run:

  • Ctrl+R: Recall the last command matching the characters you provide. Press this shortcut and start typing to search your bash history for a command.
  • Ctrl+O: Run a command you found with Ctrl+R.
  • Ctrl+G: Leave history searching mode without running a command.

bash参考手册

  • 1 Introduction

    • 1.1 What is Bash?
    • 1.2 What is a shell?
  • 2 Definitions
  • 3 Basic Shell Features
    • 3.1 Shell Syntax

      • 3.1.1 Shell Operation
      • 3.1.2 Quoting
        • 3.1.2.1 Escape Character
        • 3.1.2.2 Single Quotes
        • 3.1.2.3 Double Quotes
        • 3.1.2.4 ANSI-C Quoting
        • 3.1.2.5 Locale-Specific Translation
      • 3.1.3 Comments
    • 3.2 Shell Commands
      • 3.2.1 Reserved Words
      • 3.2.2 Simple Commands
      • 3.2.3 Pipelines
      • 3.2.4 Lists of Commands
      • 3.2.5 Compound Commands
        • 3.2.5.1 Looping Constructs
        • 3.2.5.2 Conditional Constructs
        • 3.2.5.3 Grouping Commands
      • 3.2.6 Coprocesses
      • 3.2.7 GNU Parallel
    • 3.3 Shell Functions
    • 3.4 Shell Parameters
      • 3.4.1 Positional Parameters
      • 3.4.2 Special Parameters
    • 3.5 Shell Expansions
      • 3.5.1 Brace Expansion
      • 3.5.2 Tilde Expansion
      • 3.5.3 Shell Parameter Expansion
      • 3.5.4 Command Substitution
      • 3.5.5 Arithmetic Expansion
      • 3.5.6 Process Substitution
      • 3.5.7 Word Splitting
      • 3.5.8 Filename Expansion
        • 3.5.8.1 Pattern Matching
      • 3.5.9 Quote Removal
    • 3.6 Redirections
      • 3.6.1 Redirecting Input
      • 3.6.2 Redirecting Output
      • 3.6.3 Appending Redirected Output
      • 3.6.4 Redirecting Standard Output and Standard Error
      • 3.6.5 Appending Standard Output and Standard Error
      • 3.6.6 Here Documents
      • 3.6.7 Here Strings
      • 3.6.8 Duplicating File Descriptors
      • 3.6.9 Moving File Descriptors
      • 3.6.10 Opening File Descriptors for Reading and Writing
    • 3.7 Executing Commands
      • 3.7.1 Simple Command Expansion
      • 3.7.2 Command Search and Execution
      • 3.7.3 Command Execution Environment
      • 3.7.4 Environment
      • 3.7.5 Exit Status
      • 3.7.6 Signals
    • 3.8 Shell Scripts
  • 4 Shell Builtin Commands
    • 4.1 Bourne Shell Builtins
    • 4.2 Bash Builtin Commands
    • 4.3 Modifying Shell Behavior
      • 4.3.1 The Set Builtin
      • 4.3.2 The Shopt Builtin
    • 4.4 Special Builtins
  • 5 Shell Variables
    • 5.1 Bourne Shell Variables
    • 5.2 Bash Variables
  • 6 Bash Features
    • 6.1 Invoking Bash
    • 6.2 Bash Startup Files
    • 6.3 Interactive Shells
      • 6.3.1 What is an Interactive Shell?
      • 6.3.2 Is this Shell Interactive?
      • 6.3.3 Interactive Shell Behavior
    • 6.4 Bash Conditional Expressions
    • 6.5 Shell Arithmetic
    • 6.6 Aliases
    • 6.7 Arrays
    • 6.8 The Directory Stack
      • 6.8.1 Directory Stack Builtins
    • 6.9 Controlling the Prompt
    • 6.10 The Restricted Shell
    • 6.11 Bash POSIX Mode
    • 6.12 Shell Compatibility Mode
  • 7 Job Control
    • 7.1 Job Control Basics
    • 7.2 Job Control Builtins
    • 7.3 Job Control Variables
  • 8 Command Line Editing
    • 8.1 Introduction to Line Editing
    • 8.2 Readline Interaction
      • 8.2.1 Readline Bare Essentials
      • 8.2.2 Readline Movement Commands
      • 8.2.3 Readline Killing Commands
      • 8.2.4 Readline Arguments
      • 8.2.5 Searching for Commands in the History
    • 8.3 Readline Init File
      • 8.3.1 Readline Init File Syntax
      • 8.3.2 Conditional Init Constructs
      • 8.3.3 Sample Init File
    • 8.4 Bindable Readline Commands
      • 8.4.1 Commands For Moving
      • 8.4.2 Commands For Manipulating The History
      • 8.4.3 Commands For Changing Text
      • 8.4.4 Killing And Yanking
      • 8.4.5 Specifying Numeric Arguments
      • 8.4.6 Letting Readline Type For You
      • 8.4.7 Keyboard Macros
      • 8.4.8 Some Miscellaneous Commands
    • 8.5 Readline vi Mode
    • 8.6 Programmable Completion
    • 8.7 Programmable Completion Builtins
    • 8.8 A Programmable Completion Example
  • 9 Using History Interactively
    • 9.1 Bash History Facilities
    • 9.2 Bash History Builtins
    • 9.3 History Expansion
      • 9.3.1 Event Designators
      • 9.3.2 Word Designators
      • 9.3.3 Modifiers
  • 10 Installing Bash
    • 10.1 Basic Installation
    • 10.2 Compilers and Options
    • 10.3 Compiling For Multiple Architectures
    • 10.4 Installation Names
    • 10.5 Specifying the System Type
    • 10.6 Sharing Defaults
    • 10.7 Operation Controls
    • 10.8 Optional Features
  • Appendix A Reporting Bugs
  • Appendix B Major Differences From The Bourne Shell
    • B.1 Implementation Differences From The SVR4.2 Shell
  • Appendix C GNU Free Documentation License
  • Appendix D Indexes
    • D.1 Index of Shell Builtin Commands
    • D.2 Index of Shell Reserved Words
    • D.3 Parameter and Variable Index
    • D.4 Function Index
    • D.5 Concept Index

Next: Introduction, Previous: (dir), Up: (dir) [Contents][Index]

linux_sh/bash/shell_bash参考文档/查看可用shell /命令行编辑快捷键技巧/shell job任务管理/job vs process相关推荐

  1. GNU sed 4.5 版参考文档全文翻译 各命令和随带20个示例详细解析(四)

    GNU sed 流编辑器 GNU sed 一个流编辑器(四) 5. 正则表达式:选择文本 5.1 sed正则表达式摘要 5.2 基础正则表达式和扩展正则表达式 5.3 基础正则表达式语法摘要 5.4 ...

  2. 服务器2003添加共享文档权限,Windows2003使用命令行设置共享权限与安全权限心得...

    Windows2003使用命令行设置共享权限与安全权限心得 Windows2003安装计算机等级考试系统,按系统说明对考试服务器进行安装.在安装过程中,需在服务器上创建大量考试用户和考生文件夹,且需对 ...

  3. 扫描件如何转换成word文档?扫描件转可编辑文本技巧

    软件在于数量优势,人工在于文件之质量! 以我多年的文件转换经验,没有一款PDF转换器是万能的,可能这软件转这类文件效果好,转别的就一般了,再强大的软件也有自身的不足之处,难免会遇到无法转换的文件,一份 ...

  4. PATH、cp命令、mv、文档查看命令

    which Which 查找二进制命令,按环境变量PATH路径查找(还可以查看别名) [root@localhost /]# ls /usr/bin/ls  //ls命令也是一个文件 /usr/bin ...

  5. Facebook 游戏开发更新文档 API 参考文档 v6.0

    Facebook 游戏开发更新文档 API 参考文档 v6.0 更新日志 1.排行榜 此版本全新推出排行榜 API!提供一套强大的 API, 使得游戏可获取排行榜.查询得分 情况和设置新分数(支持分数 ...

  6. Spring Boot 3.0.0-M1 Reference Documentation(Spring Boot中文参考文档) 9-16

    9. 数据 Spring Boot与多个数据技术集成,包括SQL和NoSQL. 9.1. SQL数据库 Spring Framework提供扩展支持用于与SQL数据工作,从使用JdbcTemplate ...

  7. Hibernate中文参考文档(JFIS)

    HIBERNATE - 符合Java习惯的关系数据库持久化      下一页 HIBERNATE - 符合Java习惯的关系数据库持久化 Hibernate参考文档 3.0.4 目录 前言 1. 翻译 ...

  8. [参考文档] [翻译]Oracle 12c R2优化器白皮书

    [参考文档] [翻译]Oracle 12c R2优化器白皮书 原文链接: http://www.oracle.com/technetwor ... edb-12c-1963236.pdf 第一版翻译链 ...

  9. Node.js API参考文档(目录)

    Node.js v11.5.0 API参考文档 Node.js®是基于Chrome的V8 JavaScript引擎构建的JavaScript运行时. 关于文档 用法和示例 断言测试 稳定性:2 - 稳 ...

最新文章

  1. Science:充满铵盐的环境依然发生固氮
  2. java中if结构用图表示_Java语法基础之选择结构的if语句、switch语句详解
  3. eclipse的操作
  4. Web App和Native App 谁将是未来
  5. 如何制作python代码_如何使用50行Python代码制作一个计算器
  6. 学习TensorFlow、PyTorch、机器学习、深度学习和数据结构五件套!附下载链接!...
  7. XAMPP——Apache不能启动解决方案
  8. 算法题目——使用最小花费爬楼梯(动态规划)
  9. 【数字信号调制】基于matlab无线电信号调制识别【含Matlab源码 912期】
  10. audit linux mysql_MySQL审计工具Audit Plugin安装使用
  11. SQL Server evaluation period has expired
  12. 课堂笔记 Numpy酒鬼漫步
  13. Unity期末AI足球游戏小项目(免费开源)
  14. Kurento应用开发指南(以Kurento 5.0为模板) 之四:示例教程 一对一视频呼叫
  15. JAVA:(游戏:四子连)
  16. python模块之signal信号
  17. 操作系统 --- 磁盘调度算法
  18. 如何开一场高效的迭代排期会 | 敏捷开发落地指南
  19. 切克闹!Java8新特性之方法引用
  20. 反射镜镀膜与波长关系

热门文章

  1. 解决[服务器证书无效, 连接伪装服务器]问题
  2. ajax web服务调用无效 参数值,json调用web服务,报错,无参数值!
  3. 【游戏开发实战】手把手教你在Windows上通过WSL运行Skynet,不用安装虚拟机,方便快捷(WSL | Linux | Ubuntu | Skynet | VSCode)
  4. Python爬取并绘制广州市公交线路
  5. 【linux】2022年还能用,网易真的是良心啊,网易云音乐linux版本现在还是可以使用的超赞!!官方网的下载地址还可以使用,音乐使用的是qt5进行开发的。
  6. VMware17虚拟机Linux安装教程(详解附图,带VMware Workstation 17 Pro安装)
  7. Clover 去除广告
  8. WIN10鼠标对资源管理器中文件夹右键就无响应或者卡死?
  9. 视频画中画制作,视频剪辑教程分享
  10. 期权是小公司吸引人才并留住人才的最大法宝