• Bash echo multiple lines
    30 June

    Echo Multiple Lines in Bash

    1. Overview In this article, we will see how to echo multiple lines, primarily using the echo command in various forms. Additionally, we will look at alternative methods like printf and here documents. 2. Introduction to Problem Statement Our goal is to print multiple lines with various options. The output of every method will be […]

  • Bash add character to String
    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. str="Hell" str="${str}o" echo $str Hello the${str} is used to expand the value of the str variable and then appends the string o to it, resulting […]

  • Bash split string and get last element
    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. #!/bin/bash myString="Hello:World:How:are:you?" read lastElement <<< "${myString##*:}" echo "The last element is: $lastElement" The last element is: you? In the above example, the read command is used with the ${myString##*:} parameter expansion to get the […]

  • Bash remove special characters from String
    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. #!/bin/bash string="Hello World! This is a test string." new_string="${string//[^[:alnum:]]/""}" echo "The Modified String: $new_string" The Modified String: HelloWorldThisisateststring In this example, the parameter expansion removes all special characters from the "Hello World! This is a test […]

  • Remove character from String in bash
    16 April

    Remove Character from String in Bash

    1. Overview In this article, we will explore different ways to remove characters in String in different scenarios such as removing specific characters, removing first character, removing last character, and removing first and last characters. 2. Using Parameter Expansion Bash’s built-in parameter expansion is best suited for performing string manipulation operations. Let’s explore parameter expansion […]

  • Bash remove double quotes from String
    15 April

    Remove Double Quotes from String in Bash

    1. Overview Removing double quotes from strings is a s crucial task in many scenarios, such as parsing JSON data, cleaning up user input, or preparing strings for further processing. In this article, we will see different ways to remove double quotes from String using tr, parameter expansion, awk, sed and grep. 2. Introduction to […]

  • Bash replace character in String
    15 April

    Replace Character in String in Bash

    1. Overview In this article, we will explore different ways to replace characters in String in different scenarios such as replacing the first or all occurrences of a given character, replacing all occurrences of multiple characters, and substituting a complete word. 2. Using Parameter Expansion Bash’s built-in parameter expansion can be used to manipulate String […]

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.