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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:28:43+00:00 2026-06-18T22:28:43+00:00

I am changing a bash script which has a structure as such: #somewhere in

  • 0

I am changing a bash script which has a structure as such:

#somewhere in the code
sim_counts=#... some value
function_name()
{
    set $sim_counts
    for hostname in $linux_hostnames; do
        if [ $1 -eq 0 ]; then # if sim_counts equal 0
            shift  # jump forward in sim_counts
            continue 
        fi
    # ... more code
    shift
    done
}

Then it is called in the script:

function_name

I want to introduce a parameter to this function:

#somewhere in the code
sim_counts=#... some value
function_name()
{
    ip=$1
    set $sim_counts
    for hostname in $linux_hostnames; do
        if [ $1 -eq 0 ]; then # if sim_counts equal 0
            shift  # jump forward in sim_counts
            continue 
        fi
    # ... more code
    shift
    done
}

And call the function in following way:

function_name 10.255.192.123

What should I do to avoid $1 conflict of function parameter and the other value from set command ?

  • 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-18T22:28:44+00:00Added an answer on June 18, 2026 at 10:28 pm

    If I am correctly reading the set builtin page in the Bash Reference Manual, I believe the code as you have written it will just work. Quoting from that page:

    The remaining N arguments are positional parameters and are assigned, in order, to $1, $2, … $N. The special parameter # is set to N.

    In essence, any pre-existing values for the positional variables will be blown away. The first sentence on that manual page is also interesting:

    This builtin is so complicated that it deserves its own section.

    In short, I think your code should simply work as expected. You’ve saved the initial value of $1 (from the function call) into a temporary variable; as long as you refer to $ip for that specific value, you should be good. In my own test script, it seems that $1 gets blown away as I expect it should.

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

Sidebar

Related Questions

I am trying to do a bash script that: loop over some files :
I'm trying to make a bash script in linux where some encrypted data is
Good day, i write script for building gcc on linux, my code is: #!/bin/bash
I'm doing some script on bash to plot data with gnuplot. But it doesn't
I have a bash script which calls another bash script, like so: #!/bin/bash echo
I have a bash script which runs without needing to be root . But
I'm trying to write a large python/bash script which converts my html/css mockups to
Changing a Linux C++ program which gives the user limited file access. Thus the
I have a program for some scientific simulation stuff, and as such needs to
The project I work on has some executable scripts in the repository. These scripts

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.