官术网_书友最值得收藏!

  • Bash Quick Start Guide
  • Tom Ryder
  • 421字
  • 2021-07-23 16:58:54

POSIX shell script features

Features required for the POSIX shell script include:

  • Running commands convenient syntax for running commands, including other programs, specifying arguments, environment variables, working directories, permissions masking, and other properties.
  • Variables that can be set to any string value, including manipulating process environment variables, and that can be expanded on the command line.
  • Arithmetic expansion for performing integer-based arithmetic on variables and numbers.
  • Control structures for executing code depending on the outcome of another command (if), including a specially-designed test or [ command, and repeating code until a condition is true (while).
  • Aliases as a way to abbreviate long command lines as a single word for convenience.
  • Functions to allow defining blocks of code as new commands for the purposes of the running script or interactive session.
  • Input and output redirection to specify input sources and output destinations for programs run in the shell.
  • Pipes to direct the output of one command to become the input of another.
  • Argument list through which code can iterate using a for loop.
  • Parameter expansion a means of switching between or transforming string values in assignments or command arguments.
  • Pattern matching in the form of classic Unix globs.
  • Process management in running jobs in the background, and waiting for them to complete at the desired point.
  • Compound commands to treat a group of commands as one, optionally running it in a subshell environment (subprocess).
  • Reading lines of input data including breaking them down into fields with a defined separator character.
  • Formatted strings such as the C printf(3) function in the stdio C programming language library.
  • Command substitution to use the output of a command as a variable, as part of a test, or as an argument to another command.

These features are either part of the Shell scripting language itself, or available in the POSIX-specified programs that it calls. In a sense, your shell scripts are only limited by the programs you can run with them.

By calling the grep program, for example, you can select input lines using regular expressions, even if your Shell scripting language does not itself support regular expressions. We will cover some of these essential commands in this book, even though they are not technically part of the GNU Bash distribution.

All the these features mean you can get a lot done in your Bash program even if you just use POSIX features, and your script might then run on other shells, such as dash, without much modification. All of the features are discussed in this book.

主站蜘蛛池模板: 凭祥市| 通许县| 德惠市| 高密市| 和龙市| 遵化市| 榆中县| 江永县| 周口市| 丰镇市| 武威市| 揭阳市| 南昌县| 霸州市| 南宫市| 大竹县| 鄂尔多斯市| 齐齐哈尔市| 昆山市| 宜兰县| 连州市| 溆浦县| 荃湾区| 罗山县| 确山县| 漳浦县| 谷城县| 昭通市| 读书| 湖州市| 武穴市| 惠东县| 宁陕县| 锡林郭勒盟| 柯坪县| 兴和县| 响水县| 兰溪市| 新竹市| 竹溪县| 封丘县|