900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > linux_sh/bash/shell_bash参考文档/查看可用shell /命令行编辑快捷键技巧/shell job

linux_sh/bash/shell_bash参考文档/查看可用shell /命令行编辑快捷键技巧/shell job

时间:2022-07-02 23:12:42

相关推荐

linux_sh/bash/shell_bash参考文档/查看可用shell /命令行编辑快捷键技巧/shell job

文章目录

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

sh/bash/shell_bash参考文档

references

What’s the Difference Between sh and Bash? | Baeldung on LinuxBash Reference Manual ()

conclusion

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

What Is a Shell?

A shell isa computer programthat 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 needa terminal emulatorsuch as gnome-terminal, konsole, or st.Most Linux-based operating systems come with at least oneshell program. The shell program will probably be Dash, Bash, or both.

user->terminal->shell->system

查看本机的可用shell程序

cat /etc/shells

sh

shalso known as Bourne Shell, is acommand programming language for UNIX-like systems, defined by the POSIX standards.shcan take input from either akeyboardor afile(commonly called a script file).On most Linux systems, it’simplemented by programslike the originalBourne Shell,dash, andksh.

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,shis 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

Likesh, 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 ofshand provides more extensions on top of that.

Though, most of the commands work similarly as insh.

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 useshif 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 withsh.

bash的常用功能

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

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

Quoting (Bash Reference Manual) ()

反引号(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) ()

bash中的快捷键主要有Ctrl/Alt连个键打头同样的快捷键在不同上下文中,可能表现出不同的功能!
contentsWorking With ProcessesControlling the ScreenMoving the CursorDeleting TextFixing TyposCutting and PastingCapitalizing CharactersTab CompletionWorking With Your Command Historyemacs 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+AorHome: Go to the beginning of the line.Ctrl+EorEnd: 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 betweenthe beginning of the line andthe current position of the cursor.This allows you to press Ctrl+XX toreturn to the start of the line, change something, andthen 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 characterfrom the cursor to the end of the current word, converting the characters to upper case.Alt+L:Uncapitalizeevery characterfrom 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 thefg process_namecommand.

关闭/离开当前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 theexitcommand.

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] - [~] - [-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] - [~] - [-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+PorUp Arrow: Go to the previous command in the command history. Press the shortcut multiple times to walk back through the history.Ctrl+NorDown 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 Definitions3 Basic Shell Features 3.1 Shell Syntax 3.1.1 Shell Operation3.1.2 Quoting 3.1.2.1 Escape Character3.1.2.2 Single Quotes3.1.2.3 Double Quotes3.1.2.4 ANSI-C Quoting3.1.2.5 Locale-Specific Translation 3.1.3 Comments 3.2 Shell Commands 3.2.1 Reserved Words3.2.2 Simple Commands3.2.3 Pipelines3.2.4 Lists of Commands3.2.5 Compound Commands 3.2.5.1 Looping Constructs3.2.5.2 Conditional Constructs3.2.5.3 Grouping Commands 3.2.6 Coprocesses3.2.7 GNU Parallel 3.3 Shell Functions3.4 Shell Parameters 3.4.1 Positional Parameters3.4.2 Special Parameters 3.5 Shell Expansions 3.5.1 Brace Expansion3.5.2 Tilde Expansion3.5.3 Shell Parameter Expansion3.5.4 Command Substitution3.5.5 Arithmetic Expansion3.5.6 Process Substitution3.5.7 Word Splitting3.5.8 Filename Expansion 3.5.8.1 Pattern Matching 3.5.9 Quote Removal 3.6 Redirections 3.6.1 Redirecting Input3.6.2 Redirecting Output3.6.3 Appending Redirected Output3.6.4 Redirecting Standard Output and Standard Error3.6.5 Appending Standard Output and Standard Error3.6.6 Here Documents3.6.7 Here Strings3.6.8 Duplicating File Descriptors3.6.9 Moving File Descriptors3.6.10 Opening File Descriptors for Reading and Writing 3.7 Executing Commands 3.7.1 Simple Command Expansion3.7.2 Command Search and Execution3.7.3 Command Execution Environment3.7.4 Environment3.7.5 Exit Status3.7.6 Signals 3.8 Shell Scripts 4 Shell Builtin Commands 4.1 Bourne Shell Builtins4.2 Bash Builtin Commands4.3 Modifying Shell Behavior 4.3.1 The Set Builtin4.3.2 The Shopt Builtin 4.4 Special Builtins 5 Shell Variables 5.1 Bourne Shell Variables5.2 Bash Variables 6 Bash Features 6.1 Invoking Bash6.2 Bash Startup Files6.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 Expressions6.5 Shell Arithmetic6.6 Aliases6.7 Arrays6.8 The Directory Stack 6.8.1 Directory Stack Builtins 6.9 Controlling the Prompt6.10 The Restricted Shell6.11 Bash POSIX Mode6.12 Shell Compatibility Mode 7 Job Control 7.1 Job Control Basics7.2 Job Control Builtins7.3 Job Control Variables 8 Command Line Editing 8.1 Introduction to Line Editing8.2 Readline Interaction 8.2.1 Readline Bare Essentials8.2.2 Readline Movement Commands8.2.3 Readline Killing Commands8.2.4 Readline Arguments8.2.5 Searching for Commands in the History 8.3 Readline Init File 8.3.1 Readline Init File Syntax8.3.2 Conditional Init Constructs8.3.3 Sample Init File 8.4 Bindable Readline Commands 8.4.1 Commands For Moving8.4.2 Commands For Manipulating The History8.4.3 Commands For Changing Text8.4.4 Killing And Yanking8.4.5 Specifying Numeric Arguments8.4.6 Letting Readline Type For You8.4.7 Keyboard Macros8.4.8 Some Miscellaneous Commands 8.5 Readline vi Mode8.6 Programmable Completion8.7 Programmable Completion Builtins8.8 A Programmable Completion Example 9 Using History Interactively 9.1 Bash History Facilities9.2 Bash History Builtins9.3 History Expansion 9.3.1 Event Designators9.3.2 Word Designators9.3.3 Modifiers 10 Installing Bash 10.1 Basic Installation10.2 Compilers and Options10.3 Compiling For Multiple Architectures10.4 Installation Names10.5 Specifying the System Type10.6 Sharing Defaults10.7 Operation Controls10.8 Optional Features Appendix A Reporting BugsAppendix B Major Differences From The Bourne Shell B.1 Implementation Differences From The SVR4.2 Shell Appendix C GNU Free Documentation LicenseAppendix D Indexes D.1 Index of Shell Builtin CommandsD.2 Index of Shell Reserved WordsD.3 Parameter and Variable IndexD.4 Function IndexD.5 Concept Index

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

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。