Bash
- 26 November
Check If File Contains String in Bash
1. Overview Searching for strings in text files is a common task in bash, used in scenarios like log file analysis and configuration file searches. This article explores various methods to check if file contains String, including both case-sensitive and case-insensitive approaches. 2. Introduction to Problem Statement Let’s consider a log file named server.log: [crayon-676775e070869912148874/] […]
- 20 August
Check If Output Contains String in Bash
1. Overview In this article, we will see how to check if output contains String in Bash using grep, Conditional Expressions, awk, sed commands with various options. 2. Introduction to Problem Statement We will use ls -l to list directories and files in long format and search for .txt string in the output. For example: […]
- 02 August
Check if Two Files are the Same in Bash
In this entire article, we will use the following content of three different text files to practice the provided solutions. [crayon-676775e070ef8608472455/] [crayon-676775e070efb997481636/] [crayon-676775e070efc772641397/] Using cmp Command Use the cmp command to check if two files are the same in Bash. [crayon-676775e070efd204316583/] [crayon-676775e070efe527203449/] In the above example, we initialized the file1 and file2 variables with the […]
- 02 August
Get Last Line of Output in Bash
1. Overview In this article, we will see how to get last line of output in Bash using tail, awk, sed, mapfile, and head commands with various options. 2. Introduction to Problem Statement We will use ls -l to list directories and files in long format and get the last line of output using various […]
- 02 August
Check If Boolean Is True in Bash
Using if Statement We can use an if statement with different variations to determine whether the provided Boolean variable is true. Note that the examples covered in this section will be similar. We will learn the first example in Use if with true Condition in detail, but later, we will discuss the section which will […]
- 02 August
Check If Host Is Reachable in Bash
Using ping Command Use the ping command in bash to check if the host is reachable or not. [crayon-676775e071705236446661/] [crayon-676775e071708082796004/] In this bash script, the ping command is used to check if the host "example.com" is reachable or not. In bash, the ping command is used to send ICMP Echo Request packets to the given […]
- 29 July
Set Output of Command to Variable in Bash
Using Substitution Syntax Use substitution syntax to capture the output of a single command into a variable in Bash. [crayon-676775e071868129208174/] [crayon-676775e07186b310652358/] We used the date command to get the current date and time. The date command was enclosed within the substitution syntax represented by the $(...), which we used to capture the output of the […]
- 28 July
Convert Array to Comma Separated String in Bash
Using printf Statement Use the printf statement to convert the array to a comma-separated string in Bash. [crayon-676775e071a8d491201670/] [crayon-676775e071a90141886000/] We initialized an array containing string elements. Then, we used the printf statement to convert the specified array to a comma-separated string. How? The printf statement formatted and stored the elements of the array into the […]
- 25 July
Return Array from Function in Bash
Bash cannot return values, whether a single value or an array, but it can return a status (the same as other programs). However, there are multiple turnarounds that we can use to return an array from a function. Let’s explore them below. Using nameref Feature To return the entire array from a function in Bash: […]
- 1
- 2
- 3
- …
- 5
- Nextkeyboard_arrow_right