- 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.
- Microsoft Application Virtualization Cookbook
- Spring技術內幕:深入解析Spring架構與設計
- AWS Serverless架構:使用AWS從傳統部署方式向Serverless架構遷移
- 數據結構(Python語言描述)(第2版)
- Symfony2 Essentials
- HTML5從入門到精通 (第2版)
- Go語言精進之路:從新手到高手的編程思想、方法和技巧(1)
- SQL Server實用教程(SQL Server 2008版)
- Python爬蟲、數據分析與可視化:工具詳解與案例實戰
- Spring Security Essentials
- jQuery for Designers Beginner's Guide Second Edition
- Python Machine Learning Cookbook
- Drupal Search Engine Optimization
- Python 3快速入門與實戰
- Mastering Bootstrap 4