Bash Cookbook

Ron Brash, Ganesh Naik



Create simple to advanced shell scripts and extend your system functionality with effective recipes

Key Features

  • Automate tedious and repetitive tasks
  • Create several novel applications ranging from a simple IRC logger to a webscraper
  • Become a seasoned user to efficiently manage your system

Book Description

In Linux, one of the most powerful tools that can be used almost everyday is the Bash shell. Using a collection of engaging recipes, Bash Cookbook walks you through a series of exercises designed to teach you to effectively use the Bash shell to create and execute your own scripts.

The book starts by introducing you to the basics of using the Bash shell and teaches you the fundamentals of generating any input necessary from a command. Then, you'll get to grips with a number of exercises that demonstrate the automation of daily task for sysadmins and power users. Once you have a hands-on understanding, you move onto more advanced projects that can solve real-world problems in a comprehensive and portable way on Linux. You will discover projects such as creating an application with a menu, beginning scripts on a startup, parsing and displaying human-readable information, and executing remote commands with authentication using self-generated SSH keys.

By the end of this book, you will have gained significant experience of solving real-world problems from automating routine tasks to managing your systems as well as creating your own scripts.

What you will learn

  • Understand the basics of Bash shell scripting on a Linux system
  • Gain working knowledge on how redirections and pipes interact
  • Retrieve and parse input or output of any command
  • Automate tasks such as data collection and creating and applying a patch
  • Create a script that acts like a program with different features
  • Customize your Bash shell and discover neat tricks to extend your programs
  • Compile and install shell and log commands on your system's console using Syslog

Who This Book Is For

Bash Cookbook is for power users and system administrators involved in writing Bash scripts to automate tasks. This book is also ideal for users who are interested in automating complex daily tasks.

About the Author

Ron Brash is CTO & co-founder of a successful technology consultancy that provides services in a multitude of domains, but primarily in FOSS and Linux. He has a MsComp degree from Concordia University, Montreal, and a Bachelor of Technology from BCIT, Vancouver, Canada. For over 7 years, he has been working on embedded systems, which provide security and network connectivity in industrial control systems and SCADA networks - all running an optimized embedded Linux. He participates regularly at FOSS and community events providing feedback, mini-seminars where appropriate and loves to share knowledge. In fact, the concept of sharing knowledge and improving the lives of developers, users and administrators was among the motivations for writing this book - "why can't technology be easy and accessible for everyone?" In his spare time, he explores new technologies for improved connectivity/performance and if not in front of a computer, he enjoys spending time cooking, extreme sports, being on the water and tuning performance cars.




  • 自動化繁瑣和重複的任務

  • 創建從簡單的IRC記錄器到網絡爬蟲的多種新應用程序

  • 成為一個經驗豐富的用戶,有效地管理您的系統


在Linux中,幾乎每天都可以使用的最強大的工具之一是Bash shell。使用一系列引人入勝的配方,Bash Cookbook將引導您完成一系列設計來教您如何有效地使用Bash shell來創建和執行自己的腳本的練習。

本書首先介紹了使用Bash shell的基礎知識,並教您從命令中生成任何必要的輸入的基本原理。然後,您將進行一些練習,演示系統管理員和高級用戶自動化日常任務的方法。一旦您具有實踐經驗,您將進入更高級的項目,以全面且可移植的方式解決Linux上的實際問題。您將發現一些項目,例如創建具有菜單的應用程序,開機時啟動腳本,解析和顯示可讀的人類信息,以及使用自生成的SSH密鑰進行身份驗證的遠程命令執行。



  • 了解在Linux系統上使用Bash shell腳本的基礎知識

  • 獲得有關重定向和管道交互作用的實用知識

  • 檢索和解析任何命令的輸入或輸出

  • 自動化任務,例如數據收集和創建並應用補丁

  • 創建像具有不同功能的程序一樣的腳本

  • 自定義您的Bash shell並發現擴展程序的巧妙技巧

  • 使用Syslog在系統控制台上編譯和安裝shell和日誌命令


Bash Cookbook適用於編寫Bash腳本以自動化任務的高級用戶和系統管理員。本書也非常適合對自動化複雜日常任務感興趣的用戶。


Ron Brash是一家成功的技術咨詢公司的首席技術官和聯合創始人,該公司提供多個領域的服務,主要是FOSS和Linux。他擁有蒙特利爾康科迪亞大學的MsComp學位和溫哥華BCIT的技術學士學位。他已經在嵌入式系統上工作了7年多,這些系統在工業控制系統和SCADA網絡中提供安全性和網絡連接 - 所有這些都在運行優化的嵌入式Linux。他定期參加FOSS和社區活動,提供反饋和適當的小型研討會,並樂於分享知識。事實上,分享知識和改善開發人員、用戶和管理員的生活是他撰寫本書的動機之一 - “為什麼技術不能對每個人都簡單易用和可訪問呢?”在閒暇時間,他探索新技術以改善連接性/性能,如果不在電腦前,他喜歡花時間烹飪、極限運動、在水上活動和調整性能車輛。