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

  • SEARCH
  • Home
  • 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 8835431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:15:37+00:00 2026-06-14T09:15:37+00:00

My current script does the following; It takes integer as a command line argument

  • 0

My current script does the following;

It takes integer as a command line argument and starts from 1 to N , it checks whether the numbers are divisible by 3, 5 or both of them. It simply prints out Uc for 3, Bes for 5 and UcBes for 3,5. If the command line argument is empty, it does the same operation but the loop goes to 1 to 20.

I am having this error “Too many arguments at line 11,15 and 19”.

Here is the code:

#!/bin/bash

if [ ! -z $1 ]; then
    for i in `seq 1 $1`
    do
        if [ [$i % 3] -eq 0 ]; then
            echo "Uc"
        elif [ i % 5 -eq 0 ]; then
            echo "Bes"
        elif [ i % 3 -eq 0 ] && [ i % 5 -eq 0 ]
        then
            echo "UcBes"
        else
            echo "$i"
        fi
    done
elif [ -z $1 ]
then
    for i in {1..20}
    do
        if [ i % 3 -eq 0 ]
        then
            echo "Uc"
        elif [ i % 5 -eq 0 ]
        then
            echo "Bes"
        elif [ i % 3 -eq 0 ] && [ i % 5 -eq 0 ]
        then
            echo "UcBes"
        else
            echo "$i"
        fi
    done
else
    echo "heheheh"
fi
  • 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-14T09:15:38+00:00Added an answer on June 14, 2026 at 9:15 am

    Note that [ is actually synonym for the test builtin in shell (try which [ in your terminal), and not a conditional syntax like other languages, so you cannot do:

    if [ [$i % 3] -eq 0 ]; then
    

    Moreover, always make sure that there is at least one space between [, ], and the variables that comprise the logical condition check in between them.

    The syntax for evaluating an expression such as modulo is enclosure by $((...)), and the variable names inside need not be prefixed by $:

    remainder=$((i % 3))
    if [ $remainder -eq 0 ]; then
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've built an auto-sync script that does the following: Cleanup the current location Copy
I've got a shell script which does the following to store the current day's
What is current directory of shell script? Is this current directory from which I
I used the following SQL script to enable setting current time in a field,
Currently, I have a script which does the following. If I have text file
I'm using following script to mark current page with a.active on the URL. $(function
what does it take to make my program accept command-line arguments with spaces? Yet-another
I have an SSIS package that does the following: Selects the connection strings from
I would like to run a script indefinitely. It look likes my current script,
Can anyone help me with reversing this PHP page navigation? Current script setting shows

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.