• Convert Float to Integer in Bash
    05 April

    Convert Float to Integer in Bash

    Using printf Command Use the printf command to convert float to integer in bash. [crayon-67691be40c343768164995/] [crayon-67691be40c34c809613248/] First, the float_num variable is initialized with the floating-point number. Then to convert the floating-point number to an integer, the printf command is used with the format string %.0f (specifies that printf should output the floating-point number with zero […]

  • Run String as command in Bash
    04 April

    Run String as Command in Bash

    Using eval Command Use the eval command to run a string as a command in Bash [crayon-67691be40c7ac180059366/] [crayon-67691be40c7b3763296191/] In the above code, the eval command evaluates and executes the arguments passed to it as a Bash command. The argument passed to eval is an echo Hello, world! string. This string represents the command that we […]

  • Change directory in PowerShell
    29 March

    Change Directory in PowerShell

    Using Set-Location Cmdlet Use the Set-Location cmdlet to change directory in PowerShell. [crayon-67691be40c97d209032281/] [crayon-67691be40c982682420731/] Above, we have used the Set-Location cmdlet to change the directory from C:\ to D:\ drive. In PowerShell, Set-Location is used to specify the current working directory. First, the working directory was C:\Users\DELL after using Set-Location -Path D:\ current working directory […]

  • Get last element of array in PowerShell
    29 March

    Get Last Element of Array in PowerShell

    An array is a collection of data elements stored together under a single variable name. Unlike other programming languages, the array in PowerShell contains the values of the same or different data types. It is defined using square brackets [ ] with each element separated by a comma. The array’s index starts with zero, meaning […]

  • Get Script Directory in Bash
    29 March

    Get Script Directory in Bash

    Using BASH_SOURCE Array To get the current script’s directory in a Bash, use the BASH_SOURCE array with pwd command. [crayon-67691be40cfbe411274336/] [crayon-67691be40cfc3192517019/] [crayon-67691be40cfc5070144368/] In the above example, the BASH_SOURCE variable is used with dirname to get the path of executing the script directory. In Bash, the BASH_SOURCE is an array variable containing the list of source […]

  • Get exit code of Last command in PowerShell
    28 March

    Get Exit Code of Last Command in PowerShell

    We can use different solutions to get the exit code of the last command in PowerShell, but before that, it is essential to know what does exit command means. The exit command terminates the current PowerShell script or session in PowerShell. When an exit command is executed, the PowerShell session or script will be immediately […]

  • Generate random String in Bash
    27 March

    Generate Random String in Bash

    Using $RANDOM Variable Use the $RANDOM variable with cut command to generate random string in Bash. [crayon-67691be40d3e3130910351/] [crayon-67691be40d3e7444217161/] Bash provides a built-in variable $RANDOM that generates random numbers between 0 and 32767. We can use this variable to generate random strings of any length. Here’s how to generate a random string of length 10. The […]

  • Select-String from file with regex in PowerShell
    19 March

    Select-String from File with Regex in PowerShell

    Using Select-String with Regex to Find Patterns from File There are multiple scenarios where we can use Select-String with a regular expression (also called regex) to search for particular patterns from file(s). Some of them are given below: Search a specific pattern in a single file Search a particular pattern in multiple files Search multiple […]

  • Split text file on Newline in PowerShell
    19 March

    Split Text File on NewLine in PowerShell

    Using Get-Content Cmdlet We can use multiple ways to split the specified text file into an array based on every new line. To practice those methods and commands, we will use the file.txt file having the following content. Of course, you can also create or use your text file. [crayon-67691be40d88c350779181/] Let’s continue learning the solutions […]