Skip to content
Advertisement

How to create a script in Linux that makes a pyramid of asterisks with the pattern 1, 3, 5, 7, 9, 11, 13, 15, 17 centered

I’m trying to write a shell script to print a pyramid of asterisks like this:

JavaScript

Below is my attempt so far. When I run it, I get some errors that say arithmetic expression required. What am I doing wrong?

JavaScript

Advertisement

Answer

The syntax of an arithmetic for-loop uses two semicolons, not a semicolon and a comma:

JavaScript

(The individual components may contain commas — for example, i++, j++ is an expression that increments both i and j — but that has no specific relevance to the for.)

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement