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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:04:30+00:00 2026-05-13T21:04:30+00:00

UPDATE: this is a repost of How to make shell scripts robust to source

  • 0

UPDATE: this is a repost of How to make shell scripts robust to source being changed as they run

This is a little thing that bothers me every now and then:

  1. I write a shell script (bash) for a quick and dirty job
  2. I run the script, and it runs for quite a while
  3. While it’s running, I edit a few lines in the script, configuring it for a different job
  4. But the first process is still reading the same script file and gets all screwed up.

Apparently, the script is interpreted by loading each line from the file as it is needed. Is there some way that I can have the script indicate to the shell that the entire script file should be read into memory all at once? For example, Perl scripts seem to do this: editing the code file does not affect a process that’s currently interpreting it (because it’s initially parsed/compiled?).

I understand that there are many ways I could get around this problem. For example, I could try something like:

cat script.sh | sh

or

sh -c "`cat script.sh`"

… although those might not work correctly if the script file is large and there are limits on the size of stream buffers and command-line arguments. I could also write an auxiliary wrapper that copies a script file to a locked temporary file and then executes it, but that doesn’t seem very portable.

So I was hoping for the simplest solution that would involve modifications only to the script, not the way in which it is invoked. Can I just add a line or two at the start of the script? I don’t know if such a solution exists, but I’m guessing it might make use of the $0 variable…

  • 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-13T21:04:31+00:00Added an answer on May 13, 2026 at 9:04 pm

    The best answer I’ve found is a very slight variation on the solutions offered to How to make shell scripts robust to source being changed as they run. Thanks to camh for noting the repost!

    #!/bin/sh
    {
        # Your stuff goes here
        exit
    }
    

    This ensures that all of your code is parsed initially; note that the ‘exit’ is critical to ensuring that the file isn’t accessed later to see if there are additional lines to interpret. Also, as noted on the previous post, this isn’t a guarantee that other scripts called by your script will be safe.

    Thanks everyone for the help!

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

Sidebar

Related Questions

How do you update this? I've never seen any current team that actually checks
Update: This turned into a blog post, with updated links and code, over at
Update: this question, including the title, was rephrased, see history for details I know
Duplicate of this question . update - This is not an exact duplicate. See
Update: Check out this follow-up question: Gem Update on Windows - is it broken?
Update: Please read this question in the context of design principles, elegance, expression of
Update: looks like this is indeed a WiX limitation - Cannot add 64bit com+
As made clear in update 3 on this answer , this notation: var hash
I am having virtually the same problem as this: C# Update combobox bound to
I get this error on an update panel within a popupControlExtender which is within

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.