A collection of examples in Bash scripts.
See references of this repo here.
- example1.sh: Declare variable and print it
- example2.sh: Remove variable
- example3.sh: Create readonly variable
- example4.sh: Raise error and break program
- example5.sh: Export vairable as environment vairable
- example6.sh: Special variables
- example7.sh: Special variables - get string and convert to array (by using $@)
- example8.sh: Special variables - check if program installed (by using $?)
- example9.sh: Arrays- Declare array and use it
- example10.sh: Arrays- create array from return of another command
- example11.sh: Run command inside file using backtick (`)
- example12.sh: Operators- arithmetic Operators (using expr and let)
- example13.sh: Get data from user (input)
- example14.sh: String conditions
- example15.sh: Integer conditions
- example16.sh: Operators- logical operators (-a, &&, -o, ||, !)
- example17.sh: File conditions
- example18.sh: Check SUID and GUID in files
- example19.sh: If statement
- example20.sh: Case Block
- example21.sh: Select Loop
- example22.sh: For Loop
- example23.sh: While Loop
- example24.sh: While Loop- more complex example
- example25.sh: Until Loop
- example26.sh: Until Loop- more complex example
- example27.sh: Loop- break command
- example28.sh: Loop- continue command
- example29.sh: Redirect- Introduction and simple commands
- example30.sh: Redirect- Appends to the file
- example31.sh: Redirect- Discard both stdout and stderr
- example32.sh: Redirect- Send the contents of a file to the stdin of a command
- example33.sh: Redirect- Complex redirection
- example34.sh: Redirect- Open custom file descriptor
- example35.sh: Redirect- Open a file for read and write with fd
- example36.sh: Redirect- List all file descriptors
- example37.sh: Redirect- tee and pip and pip&
- example38.sh: Get argument from terminal
- example39.sh: Function- Create functions and call it
- example40.sh: Function- Define and call function for calculate rectangle area
- example41.sh: Function- Get Return Value from Function
- example42.sh: Working with date
- example43.sh: Sleep Command
- mix_exercise1.sh: Install program after some check like directory exists, ownership and etc.
- mix_exercise2.sh: Create menu in terminal and choice opetions
- mix_exercise3.sh: Read a file line by line
- mix_exercise4.sh: Read the first three columns/fields from a file into variables
- mix_exercise5.sh: Read first line of file and put it into variable using redirection
- mix_exercise6.sh: Create directory if not exist
- mix_exercise7.sh: 4 arthimetrics operators
- mix_exercise8.sh: Factorial calculator
- mix_exercise9.sh: Lower case string
- mix_exercise10.sh: Upper case string
- one-line1.sh: Get size of file
- one-line2.sh: Extract file name from the path
- one-line3.sh: Generate the alphabet from a to z
- one-line4.sh: Genearte the alaphbet from a to z without space
- one-line5.sh: Pading numbers with leading zero
- one-line6.sh: Combine two set of strings
- one-line7.sh: Find and replace first occurrence with: ${var/find/replace}
- one-line8.sh: Find and replace all occurrence with: ${var//find/replace}
- one-line9.sh: Extract a substring from a string
- one-line10.sh: Change upper case to lower case and vice versa
- one-line11.sh: Get usage percent of specific file system
- Bash Reference Manual: A brief description of the features that are present in the Bash shell (version 5.2, 19 September 2022)