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

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

Distinguishing command types

The commands you can use in a Bash script fall into three major categories:

  • Shell builtin commands: Included in Bash itself. These commands don't correspond to executable program files on your system; they are implemented in the bash binary itself. Examples are echo, type, and source.
  • Runtime commands: Defined in the shell at runtime, and written in the Bash language. These can be aliases or functions. They don't have executable program files of their own on disk either, and are defined at runtime during a Bash session, often by reading startup files. Examples vary between systems and users.
  • System commands: Invoke executable program files on your filesystem. These are the only kinds of commands that can also be run outside of Bash. Examples are grep, ping, and rm.

The executable programs called by system commands may be written in any language. Bash can be used to specify how these programs run, where their input comes from, how their output is processed, and how their success or failure changes the execution of the rest of the script.

We will explore useful commands in the first and third categories in this chapter. Runtime commands (aliases and functions) are discussed in Chapter 7, Scripts, Functions, and Aliases. In this chapter, you will learn how to use these essential builtin commands:

  • type: Finding what a command is
  • echo: Printing arguments
  • printf: Printing formatted arguments
  • pwd: Printing the current directory
  • cd: Changing the current directory
  • set: Viewing and setting shell properties
  • declare: Managing variables and functions
  • test, [, [[: Evaluating expressions

You will also learn how to use these system commands, which are not part of Bash itself:

  • ls: Listing files for users
  • mv: Moving and renaming files
  • cp: Copying files
  • rm and rmdir: Deleting files and directories
  • grep: Matching patterns
  • cut: Extracting columns from data
  • wc: Counting lines, words, and characters
  • find: Iterating through a file tree
  • sort and uniq: Sorting and de-duplicating input
We will not be covering the use of interactive text editors, such as  emacs, nano, and  vi, due to space concerns. It's a very good idea for an aspiring Bash programmer to learn how to use one of those editors, however! Your author recommends vi, especially the Vim implementation.
主站蜘蛛池模板: 阳新县| 祥云县| 沾益县| 临西县| 嘉定区| 福州市| 吴堡县| 肇庆市| 曲阜市| 乾安县| 望奎县| 柯坪县| 桂林市| 万载县| 大埔区| 获嘉县| 乌拉特中旗| 任丘市| 京山县| 嘉峪关市| 双牌县| 孟津县| 勐海县| 华池县| 收藏| 勃利县| 德阳市| 侯马市| 永春县| 济南市| 醴陵市| 开远市| 承德县| 招远市| 如皋市| 忻州市| 新郑市| 德惠市| 阳谷县| 太和县| 木兰县|