Programs for printing different patterns in Bash
Given the number N which represents the number of rows and columns, print the different following patterns in Bash.
- Pattern-1:
Input: 6 Output: # ## ### #### ##### ######Use nested loop to print the given pattern. The first loop represents the row and the second loop represents the column.
# Program to print the# given pattern# Static input for NN=5# variable used for# while loopi=0j=0while[ $i -le`expr$N - 1` ]doj=0while[ $j -le`expr$N - 1` ]doif[ `expr$N - 1` -le`expr$i + $j` ]then# Print the patternecho-ne"#"else# Print the spaces requiredecho-ne" "fij=`expr$j + 1`done# For next lineechoi=`expr$i + 1`donechevron_rightfilter_noneOutput:
# ## ### #### ##### - Pattern-2:
Input: 3 Output: # ### #####Use nested loops to print the left part and right part of the pattern. The details are explained in the code:
# Program in Bash to# print pyramid# Static input to the# numberp=7;for((m=1; m<=p; m++))do# This loop print spaces# requiredfor((a=i; a<=p; a++))doecho-ne" ";done# This loop print the left# side of the the pyramidfor((n=1; n<=m; n++))doecho-ne"#";done# This loop print right# side of the pryamid.for((i=1; i<m; i++))doecho-ne"#";done# New lineecho;donechevron_rightfilter_noneOutput:
# ### ##### ####### ######### ########### #############
Recommended Posts:
- Average of given numbers in Bash
- Fibonacci Series in Bash
- Simple Calculator in Bash
- Bash program to find A to the power B
- Bash program to check if the Number is a Prime or not
- Bash program to check if the Number is a Palindrome
- Sorting an array in Bash using Bubble sort
- Bash Script to get Low Battery Alert in Linux
- Bash shell script to swap two numbers
- Bash shell script to find sum of digits
- Useful and time saving bash commands in Linux
- Write a bash script to print a particular line from a file
- How to Compile and Run C/C++/Java Programs in Linux
- What is Linux System Administration?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



