Unix
- 04 May
Bash Add Character to String
We can also use these methods to add a string to the given string as well. Using $ Operator Use the $ operator to add character to string in Bash. [crayon-6767fbb724688073484122/] [crayon-6767fbb724691591711031/] the${str} is used to expand the value of the str variable and then appends the string o to it, resulting in the string […]
- 03 May
Bash Create Folder if Not Exists
To run the following commands, directly write the command in the bash terminal and execute them. Using mkdir -p Command Use the mkdir -p command to create folder if not exists in Bash [crayon-6767fbb725ed0338896932/] The mkdir is used to create the directory. The -p created all the intermediate directories if they didn’t exist. The /path/to/directory […]
- 02 May
If Not Condition in Bash
In Bash, figuring out how you interpret the term if not condition before digging into the solutions is mandatory. For example, are you taking as negating the condition/expression, which means make the condition/expression False if it is True and vice versa? Or, you want to make some comparisons to assess inequality; this comparison can be […]
- 16 April
Bash Split String and Get Last Element
Using read Command Use the read command with parameter expansion to split the string and get the last element in Bash. [crayon-6767fbb7262ec554183239/] [crayon-6767fbb7262f0695345185/] In the above example, the read command is used with the ${myString##*:} parameter expansion to get the last element of the string which is then assigned to the lastElement variable using the […]
- 16 April
Add Comma to End of Each Line in Bash
1. Overview Adding characters like commas to the end of each line in a text file is a common operation in file processing and data manipulation. This task can be especially useful in formatting data files for CSV conversion or similar purposes. 2. Introduction to Problem Statement Imagine we have a text file named input.txt […]
- 16 April
Round to 2 Decimal Places in Bash
1. Overview In Bash scripting, dealing with numbers and specifically rounding them to a certain number of decimal places is a common task. For example, given a number like 3.14159, the goal is to round it to two decimal places, resulting in 3.14. This article explores various methods to achieve this in Bash, focusing on […]
- 16 April
Bash Log Output to File
Using Redirect Operator To log the output of a bash command to a file, use the redirect operator. There are two types of redirect Operator: > (Standard Output Redirect Operator): It redirects the output of a command to a file and overwrites the file’s contents. >> (Standard Output Append Operator): It appends the command’s output […]
- 16 April
Bash Remove Special Characters from String
Using Parameter Expansion Use the parameter expansion with regex to remove the special characters from a string in Bash. [crayon-6767fbb727d8e079929628/] [crayon-6767fbb727d95094510003/] In this example, the parameter expansion removes all special characters from the "Hello World! This is a test string." string. We can observe that our input string contained two special characters, the exclamation marks […]
- 16 April
Bash Get Absolute Path from Relative Path
When working with shell scripts, it’s common to need to get the absolute path of a file or directory from its relative path. However, before we dive into how to get the absolute path from a relative path, we must learn the difference between the two types of paths. The relative path is relative to […]
- 1
- 2
- 3
- …
- 5
- Nextkeyboard_arrow_right