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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:21:38+00:00 2026-05-25T17:21:38+00:00

I have noticed some weird behavior when sourcing another script within my shell script.

  • 0

I have noticed some weird behavior when sourcing another script within my shell script. The script that I am sourcing to setup the environment in my shell script takes an optional argument, e.g.

source setup.sh version1

However in my shell script I have also have command line argument variables. For example:

./myscript.sh TEST 1

Inside myscript.sh:

#!/bin/zsh
source setup.sh
echo ROOT version setup $ROOT_SYS
...more of the script

The problem that I have noticed with my script above is that the $1 argument (TEST in this example) is used in the source setup.sh command. This causes the command to become

source setup.sh TEST

which of course fails as setup.sh does not have a version TEST.

I solved this problem by editing my script to below.

#!/bin/zsh
source setup.sh version1
echo ROOT version setup $ROOT_SYS
...more of the script

The source command now does not pick up the $1 argument.

Why/How does the source command pick up the $1 argument when I am running my shell script?

  • 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-25T17:21:38+00:00Added an answer on May 25, 2026 at 5:21 pm

    This is because source executes the code of setup.sh as if it was in place, so when setup.sh access, say, $1, the value it has is that of the first argument of the actual script. If you want to avoid that you could either execute it:

    setup.sh
    

    or, if you need to get back some variables or values from it, change it to return the result in form of an output, something like:

    ROOT_SYS=`setup.sh`
    

    Finally, as you figured out, the source keywords also allows providing arguments to the scripts, but it bypasses current arguments if you don’t provide any.

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

Sidebar

Related Questions

We have noticed a weird error when calling ToLower() on certain strings. The input
I've only just started looking at Dapper.net and have just been experimenting with some
All files seems to have run through the build script without any problems except
I've noticed that when you copy a range in excel (copy as a picture
Okay, this is pretty weird. I made an app that listens for changes inside
I'm getting some weird antialising happening on my transparent PNGs in IE - the
I was trying to make my own php mktime(); using my default timezone *(America/Sao_Paulo)*.
I want to write integration application test to test the full CRUD operations. I
My mobile titanium app is loading data from a remote url, in the form

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.