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 898375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:01:57+00:00 2026-05-15T15:01:57+00:00

I want to pass many arguments to a shell script which I don’t know

  • 0

I want to pass many arguments to a shell script which I don’t know how many arguments they are going to be and I want to handle them. I did the following code:

int=$1
src=$2

r=$3
string=$4

duration=$5

./start.sh $int $r $src "$string"
sleep $duration

shift; shift; shift; shift; shift

while [ $# -gt 2 ]
do
  r=$1
  string=$2
  duration=$3
  ./change.sh $int $r "$string"
  sleep $duration
  shift; shift; shift
done

That works but only for one time, now I want this script to run all the time, I mean using while 1 but that won’t work this way because the argument list is empty at the end of that code!

Is there any way to do something like the following “pseudo code” in shell scripts:

for( i=0 ; i<arguments.count; i++ ){
   //do something with arguments[i]
}

or copying the arguments array into another array so that I can use it later the way I want.
I mean can I copy $* or $@ or arg into another array?

Any help is highly appreciated.

  • 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-05-15T15:01:57+00:00Added an answer on May 15, 2026 at 3:01 pm

    The number of arguments is stored in the parameter #, which can be accessed with $#.

    A simple loop over all arguments can be written as follows:

    for arg
    do
        # do something with the argument "arg"
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I want to pass a string which contains Spanish text that could be
My $SHELL is tcsh. I want to run a C shell script that will
I'm afraid of varargs. I don't know what to use them for. Plus, it
I read many files from my system. I want to read them faster, maybe
Products are grouped for inspected and pass/fail on about 20 criteria. They want a
I want to pass an integer value to a form in .Net so that
I want to pass an int list (List) as a declarative property to a
I want to pass an enum value as command parameter in WPF, using something
I want to pass in the tType of a class to a function, and
I want to pass some parameters to my MVC UserControl like ShowTitle(bool) and the

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.