- Bash Cookbook
- Ron Brash Ganesh Naik
- 460字
- 2021-07-23 19:17:33
Introduction
Hopefully, the previous Bash crash course chapter provided more than a hint of the utility and power of Bash. On the other hand, this chapter introduces several bolt-on technologies to make Bash even more extensive when searching for items and text, or automating file explorer/file system operations.
By itself, Bash is merely a powerful scripting language, but much of Bash's flexibility comes from being able to "glue" other technologies (tools or languages) together to make the output more useful. In other words, Bash is a base platform similar to how some auto/car lovers choose a particular platform before making their modifications. Will a modified car do everything, even with enhancements? Certainly not, but it can make it more powerful or useful in specific cases, and at least provides four wheels for movement.
Not only do common scripts contain a series of commands for automation, they often include logic to modify strings such as the following:
- Removing trailing characters
- Replacing sections of words (substrings)
- Searching for strings in files
- Finding files
- Testing file types (directory, file, empty, and so on)
- Performing small calculations
- Limiting the scope of searches or data (filtering)
- Modifying the contents of variables (strings inside of string variables)
This logic that modifies, limits, and even replaces input/output data can be very powerful when you need to execute broad searches for a specific string or when you have copious amounts of data. Terminals chock; full of output or massive data files can be very daunting to explore!
However, there is one very important concept that still needs to be discussed, and that is recursive functionality. Recursive functionality can apply to script functions, logic, and even a command operation. For example, you can use grep to recursively crawl an entire directory until no more files remain, or you can recursively execute a function inside of itself until a condition is met (for example, printing a single character at a time within a string):
# e.g. File system
# / (start here)
# /home (oh we found home)
# /home/user (neat there is a directory inside it called user)
# /home/user/.. (even better, user has files - lets look in them too)
# /etc/ # We are done with /home and its "children" so lets look in /etc
# ... # Until we are done
This chapter is all about limiting data, utilizing it, modifying it, internationalizing it, replacing it, and even searching for it in the first place.
- Python 3.7網絡爬蟲快速入門
- JavaScript修煉之道
- Scratch真好玩:教小孩學編程
- 區塊鏈:以太坊DApp開發實戰
- INSTANT OpenNMS Starter
- Redis Essentials
- PHP+MySQL網站開發項目式教程
- JavaScript:Moving to ES2015
- JavaScript入門經典
- 數據結構案例教程(C/C++版)
- Learning AWS
- Buildbox 2.x Game Development
- Getting Started with Python
- Xamarin Cross-Platform Development Cookbook
- Managing Windows Servers with Chef