100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Popular Bash Notes for Professionals $7.49   Add to cart

Interview

Popular Bash Notes for Professionals

 7 views  0 purchase
  • Course
  • Institution
  • Book

Most Important Study Notes

Preview 4 out of 204  pages

  • December 30, 2021
  • 204
  • 2021/2022
  • Interview
  • Unknown
  • Unknown
  • Secondary school
  • 3
avatar-seller
Bash
Bash
Notes for Professionals




Notes for Professionals




100+ pages
of professional hints and tricks


Disclaimer
GoalKicker.com This is an unocial free book created for educational purposes and is
not aliated with ocial Bash group(s) or company(s).
Free Programming Books All trademarks and registered trademarks are
the property of their respective owners

,Contents
About ................................................................................................................................................................................... 1
Chapter 1: Getting started with Bash ................................................................................................................. 2
Section 1.1: Hello World ................................................................................................................................................. 2
Section 1.2: Hello World Using Variables ..................................................................................................................... 4
Section 1.3: Hello World with User Input ...................................................................................................................... 4
Section 1.4: Importance of Quoting in Strings ............................................................................................................ 5
Section 1.5: Viewing information for Bash built-ins .................................................................................................... 6
Section 1.6: Hello World in "Debug" mode .................................................................................................................. 6
Section 1.7: Handling Named Arguments .................................................................................................................... 7
Chapter 2: Script shebang ........................................................................................................................................ 8
Section 2.1: Env shebang .............................................................................................................................................. 8
Section 2.2: Direct shebang .......................................................................................................................................... 8
Section 2.3: Other shebangs ........................................................................................................................................ 8
Chapter 3: Navigating directories ...................................................................................................................... 10
Section 3.1: Absolute vs relative directories .............................................................................................................. 10
Section 3.2: Change to the last directory .................................................................................................................. 10
Section 3.3: Change to the home directory .............................................................................................................. 10
Section 3.4: Change to the Directory of the Script .................................................................................................. 10
Chapter 4: Listing Files ............................................................................................................................................ 12
Section 4.1: List Files in a Long Listing Format ......................................................................................................... 12
Section 4.2: List the Ten Most Recently Modified Files ............................................................................................ 13
Section 4.3: List All Files Including Dotfiles ................................................................................................................ 13
Section 4.4: List Files Without Using `ls` ..................................................................................................................... 13
Section 4.5: List Files ................................................................................................................................................... 14
Section 4.6: List Files in a Tree-Like Format ............................................................................................................. 14
Section 4.7: List Files Sorted by Size .......................................................................................................................... 14
Chapter 5: Using cat .................................................................................................................................................. 16
Section 5.1: Concatenate files ..................................................................................................................................... 16
Section 5.2: Printing the Contents of a File ............................................................................................................... 16
Section 5.3: Write to a file ........................................................................................................................................... 17
Section 5.4: Show non printable characters ............................................................................................................. 17
Section 5.5: Read from standard input ..................................................................................................................... 18
Section 5.6: Display line numbers with output ......................................................................................................... 18
Section 5.7: Concatenate gzipped files ..................................................................................................................... 18
Chapter 6: Grep ........................................................................................................................................................... 20
Section 6.1: How to search a file for a pattern ......................................................................................................... 20
Chapter 7: Aliasing ..................................................................................................................................................... 21
Section 7.1: Bypass an alias ........................................................................................................................................ 21
Section 7.2: Create an Alias ........................................................................................................................................ 21
Section 7.3: Remove an alias ..................................................................................................................................... 21
Section 7.4: The BASH_ALIASES is an internal bash assoc array .......................................................................... 22
Section 7.5: Expand alias ............................................................................................................................................ 22
Section 7.6: List all Aliases .......................................................................................................................................... 22
Chapter 8: Jobs and Processes ........................................................................................................................... 23
Section 8.1: Job handling ............................................................................................................................................ 23
Section 8.2: Check which process running on specific port .................................................................................... 25

, Section 8.3: Disowning background job .................................................................................................................... 25
Section 8.4: List Current Jobs ..................................................................................................................................... 25
Section 8.5: Finding information about a running process ..................................................................................... 25
Section 8.6: List all processes ..................................................................................................................................... 26
Chapter 9: Redirection ............................................................................................................................................. 27
Section 9.1: Redirecting standard output .................................................................................................................. 27
Section 9.2: Append vs Truncate ............................................................................................................................... 27
Section 9.3: Redirecting both STDOUT and STDERR .............................................................................................. 28
Section 9.4: Using named pipes ................................................................................................................................. 28
Section 9.5: Redirection to network addresses ........................................................................................................ 30
Section 9.6: Print error messages to stderr .............................................................................................................. 30
Section 9.7: Redirecting multiple commands to the same file ............................................................................... 31
Section 9.8: Redirecting STDIN .................................................................................................................................. 31
Section 9.9: Redirecting STDERR ............................................................................................................................... 32
Section 9.10: STDIN, STDOUT and STDERR explained ............................................................................................ 32
Chapter 10: Control Structures ............................................................................................................................ 34
Section 10.1: Conditional execution of command lists ............................................................................................. 34
Section 10.2: If statement ............................................................................................................................................ 35
Section 10.3: Looping over an array .......................................................................................................................... 36
Section 10.4: Using For Loop to List Iterate Over Numbers .................................................................................... 37
Section 10.5: continue and break ............................................................................................................................... 37
Section 10.6: Loop break ............................................................................................................................................. 37
Section 10.7: While Loop ............................................................................................................................................. 38
Section 10.8: For Loop with C-style syntax ............................................................................................................... 39
Section 10.9: Until Loop ............................................................................................................................................... 39
Section 10.10: Switch statement with case ................................................................................................................ 39
Section 10.11: For Loop without a list-of-words parameter ..................................................................................... 40
Chapter 11: true, false and : commands .......................................................................................................... 41
Section 11.1: Infinite Loop ............................................................................................................................................. 41
Section 11.2: Function Return ...................................................................................................................................... 41
Section 11.3: Code that will always/never be executed ........................................................................................... 41
Chapter 12: Arrays ...................................................................................................................................................... 42
Section 12.1: Array Assignments ................................................................................................................................. 42
Section 12.2: Accessing Array Elements .................................................................................................................... 43
Section 12.3: Array Modification ................................................................................................................................. 43
Section 12.4: Array Iteration ....................................................................................................................................... 44
Section 12.5: Array Length .......................................................................................................................................... 45
Section 12.6: Associative Arrays ................................................................................................................................. 45
Section 12.7: Looping through an array .................................................................................................................... 46
Section 12.8: Destroy, Delete, or Unset an Array ..................................................................................................... 47
Section 12.9: Array from string ................................................................................................................................... 47
Section 12.10: List of initialized indexes ...................................................................................................................... 47
Section 12.11: Reading an entire file into an array .................................................................................................... 48
Section 12.12: Array insert function ............................................................................................................................ 48
Chapter 13: Associative arrays ............................................................................................................................ 50
Section 13.1: Examining assoc arrays ........................................................................................................................ 50
Chapter 14: Functions ............................................................................................................................................... 52
Section 14.1: Functions with arguments ..................................................................................................................... 52
Section 14.2: Simple Function ..................................................................................................................................... 53
Section 14.3: Handling flags and optional parameters ........................................................................................... 53

, Section 14.4: Print the function definition .................................................................................................................. 54
Section 14.5: A function that accepts named parameters ...................................................................................... 54
Section 14.6: Return value from a function ............................................................................................................... 55
Section 14.7: The exit code of a function is the exit code of its last command ..................................................... 55
Chapter 15: Bash Parameter Expansion .......................................................................................................... 57
Section 15.1: Modifying the case of alphabetic characters ..................................................................................... 57
Section 15.2: Length of parameter ............................................................................................................................ 57
Section 15.3: Replace pattern in string ...................................................................................................................... 58
Section 15.4: Substrings and subarrays .................................................................................................................... 59
Section 15.5: Delete a pattern from the beginning of a string ................................................................................ 60
Section 15.6: Parameter indirection ........................................................................................................................... 61
Section 15.7: Parameter expansion and filenames .................................................................................................. 61
Section 15.8: Default value substitution ..................................................................................................................... 62
Section 15.9: Delete a pattern from the end of a string .......................................................................................... 62
Section 15.10: Munging during expansion ................................................................................................................. 63
Section 15.11: Error if variable is empty or unset ...................................................................................................... 64
Chapter 16: Copying (cp) ......................................................................................................................................... 65
Section 16.1: Copy a single file .................................................................................................................................... 65
Section 16.2: Copy folders ........................................................................................................................................... 65
Chapter 17: Find ........................................................................................................................................................... 66
Section 17.1: Searching for a file by name or extension .......................................................................................... 66
Section 17.2: Executing commands against a found file ......................................................................................... 66
Section 17.3: Finding file by access / modification time .......................................................................................... 67
Section 17.4: Finding files according to size .............................................................................................................. 68
Section 17.5: Filter the path ......................................................................................................................................... 69
Section 17.6: Finding files by type .............................................................................................................................. 70
Section 17.7: Finding files by specific extension ........................................................................................................ 70
Chapter 18: Using sort .............................................................................................................................................. 71
Section 18.1: Sort command output ........................................................................................................................... 71
Section 18.2: Make output unique .............................................................................................................................. 71
Section 18.3: Numeric sort .......................................................................................................................................... 71
Section 18.4: Sort by keys ........................................................................................................................................... 72
Chapter 19: Sourcing ................................................................................................................................................. 74
Section 19.1: Sourcing a file ......................................................................................................................................... 74
Section 19.2: Sourcing a virtual environment ........................................................................................................... 74
Chapter 20: Here documents and here strings ........................................................................................... 76
Section 20.1: Execute command with here document ............................................................................................. 76
Section 20.2: Indenting here documents .................................................................................................................. 76
Section 20.3: Create a file ........................................................................................................................................... 77
Section 20.4: Here strings ........................................................................................................................................... 77
Section 20.5: Run several commands with sudo ..................................................................................................... 78
Section 20.6: Limit Strings .......................................................................................................................................... 78
Chapter 21: Quoting ................................................................................................................................................... 80
Section 21.1: Double quotes for variable and command substitution .................................................................... 80
Section 21.2: Dierence between double quote and single quote ......................................................................... 80
Section 21.3: Newlines and control characters ......................................................................................................... 81
Section 21.4: Quoting literal text ................................................................................................................................. 81
Chapter 22: Conditional Expressions ................................................................................................................ 83
Section 22.1: File type tests ......................................................................................................................................... 83

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller waseemmirza2262. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $7.49. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

85443 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$7.49
  • (0)
  Add to cart