Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7868267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:56:54+00:00 2026-06-03T00:56:54+00:00

This program is suppose to accept a number from the user and print that

  • 0

This program is suppose to accept a number from the user and print that many prime numbers. For some reason the program doesn’t work. I am new to bash scripting and this is my first program. To my eyes everything seems to be correct. Please tell me where I went wrong.

echo Enter num
read n
i=2
j=2

for(( i=2; i <= n; i++ ))
do

for(( j=2; j < i-1; j++ ))
do

if [i % j == 0];
then
break
fi


if [i == j];
then
echo "  $i"
fi
done
done

This is the output I get

Enter num
20
prime.sh: line 12: [i: command not found
prime.sh: line 18: [i: command not found
prime.sh: line 12: [i: command not found
prime.sh: line 18: [i: command not found
 .
 .
 .

After making the suggested changes

read -p "Enter a  number : " n
i=2
j=2
for(( i=2; i <= n; i++ ))
do
    for(( j=2; j <= i-1; j++ ))
    do
        if [ $(( i % j )) == 0 ]
        then
            break
        fi
        if [ i == j ]
        then
            echo "  $i"
        fi
    done
done

I was able to run the program but it didn’t produce any result

https://i.stack.imgur.com/Fd1se.png

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:56:55+00:00Added an answer on June 3, 2026 at 12:56 am

    You need to place a space after the [ because [ is an application.

    And you can’t make calculations between the brackets. You will need to tell bash it needs to calculate the values. So you would need to change line 11 to if (( i % j == 0 )).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This program takes the first number in a file and indicates how many numbers
I'm making a program that makes a fractal, and the user is suppose to
Suppose I have a simple C++ program that takes in inputs and outputs some
I've built this program to read a user name from a file. It checks
Say suppose I am running a java program through command line. And this program
This program is supposed to determine how many units are stored in the value
I am supposed to modified this Sierpinski's triangle program to count the number of
This program stores pairs in a map, counting the number of times a word
I am trying some programs in c face a problem with this program can
#include<stdlib.h> #include<stdio.h> #include<string.h> //This program is a sorting application that reads a sequence of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.