Tag archives for scripting
How to concatenate string variables in Bash
Here are few preferred ways to concatenate string variables in bash script Concatenate string variables in Bash the variable one after another in echo #!/bin/bash var1="Techieroop" var2="${var1} Tutorial" echo "${var2}" ##output Techieroop Tutorial 2. Use += assignment operator: #!/bin/bash var="Techieroop" var+=" Tutorial" echo "$var" ##output Techieroop Tutorial Second method can be…
How to check if a string contains a substring in Bash
Here are the couple of methods to check if a string contains a substring in bash shell script. Methods to check if string contains a substring in Bash Method 1: Use regular expression #!/bin/bash str='Techieroop: Solution for DevOps & Open Source Technology' if [[ $str =~ "DevOps" ]]; then echo…
How to check if file does not exist in Bash?
Check if file does not exist in Bash Script? You can use -f option in bash script to check if file does not exist. Check if file does not exists if ; then echo "File not found" fi Parameterize file name in script to check if file doesn't exist #!/bin/bash…
How to check if a directory exists in a bash script?
How to check if a directory exists in a bash script? In shell script implementation you might come across use case where you need to perform some operation in a directory, but what if directory is not present then your script might break. To avoid the failure and display user…
Find the largest and smallest number in python using for loop
Write a python program to find the largest and smallest number in python using for loop Assign first element of an array to largest(lt) and smallest (st) value the array by using for loop If element of array a is smaller than first element of variable st then assign array…
Find two numbers whose sum is equal to a given number in sorted array
Find two numbers whose sum is equal to a given number in sorted array In order to find the sum of the two array elements you need to traverse in array and check the sum of each element. Let's take an example of below sorted array in which we have to perform below iteration to find the sum of the array element. First Iteration: 1 51 61 81 10 Second…
Bubble sort program in python
Write a Program in Python to execute Bubble sort program What is Bubble Sort Program ? Bubble sort is a simple sorting algorithm that compares adjacent elements and swaps them if they are in the wrong order. It will compares through the list until the list is completely sorted. Let's…
Program to print Fibonacci series in python
The Fibonacci numbers, commonly refers as Fibonacci sequence, in which each number is the sum of the two preceding numbers, starting from 0 and 1. The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... # Program to print Fibonacci sequence…
Reverse String in Python using Recursion
Let's understand what is the recursion in programming with reverse string in Python program Recursion is a process by which a function calls itself directly or indirectly. The corresponding function is called as recursive function When Should I use Recursion ? Recursion is made for solving problems that can be broken down into smaller,…
Shell Script Questions and Answers
Please find below list of Shell Script Questions and Answers. Shell Script Questions and Answers 1. Given two integers, X and Y , find their sum, difference, product, and quotient. Constraints X >= -100 Y <= 100 and Y != 100 read X case ${X#} in ** | '') echo "Not an…









