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

  • Bash Quick Start Guide
  • Tom Ryder
  • 358字
  • 2021-07-23 16:58:55

Choosing when to apply Bash

There are some tasks for which shell scripting in general, and Bash in particular, are especially well-suited:

  • Prototyping: Short Bash programs are quick and easy to write. It's quite common to "hack together" a simple script in Bash for later replacement by a script or program in a more advanced programming language that requires more effort to write and maintain.

  • Interactive system administration: A Bourne-style shell is assumed in very many contexts in Unix, and almost all of the system documentation you read will tell you to issue commands in a Bourne-style shell. This makes it a natural choice for a scripting language.

  • Automation: If you have a set of commands you often run together, making a script for them is as simple as writing them all into a text file, each on a new line, and making that file executable.

  • Connecting programs together: Like all Shell scripting languages, Bash specializes in moving data to and from files and between processes. Many programs are designed to work together in this way.

  • Filtering and transforming text input: Some programs, however, aren't designed to cooperate in this way, and they require some data filtering and transformation in the middle. Bash can be a very convenient language for doing this, and it's also a good language to call other tools such as awk or sed to do it for you.

  • Navigating the Unix filesystem: In Bash, it does not require much code to navigate and iterate through the filesystem, discovering, filtering, and processing files within it at runtime. Coupled with the find tool, especially a high-powered version such as GNU find, a lot can be done in a pattern over a filesystem with relatively little code.

  • Basic pattern-matching on strings: Bash has features that make it good for basic pattern-matching on strings, especially filenames and path names, with parameter expansion.

  • Portability: Bash works on and is packaged for a huge variety of Unix-like systems. POSIX shell script is even more widely supported. If you need to know your script and its runtime will remain portable to many Unix-like systems, Bash might be a good choice.

主站蜘蛛池模板: 通州市| 蓝山县| 荆门市| 桓台县| 南皮县| 富平县| 政和县| 巴林右旗| 龙陵县| 连州市| 怀安县| 慈利县| 佛教| 光山县| 镶黄旗| 汝州市| 大埔县| 中卫市| 府谷县| 浦东新区| 遵义市| 北辰区| 松原市| 安福县| 紫金县| 宜州市| 上蔡县| 盐城市| 卢龙县| 迁西县| 比如县| 汉中市| 中山市| 曲松县| 嘉禾县| 潮安县| 克什克腾旗| 宁城县| 安溪县| 汉沽区| 忻城县|