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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:31:49+00:00 2026-06-15T11:31:49+00:00

Ok so I was wondering if it is possible to save like a variable

  • 0

Ok so I was wondering if it is possible to save like a variable in bash. I am writing a script where you build like farms and mines and I was just wondering if it is possible to bring back those variables even after I stopped the program and then got back on. So lets say I have built 4 farms farms would be farm=4, can I bring this variable back somehow? I know how to make a page that you can make a high scores list on (Which I did for a guessing game.), but this I don’t know if it is possible in bash.

  • 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-15T11:31:51+00:00Added an answer on June 15, 2026 at 11:31 am

    You can save all needed variables in a file (using here-doc):

    cat<<EOF>/path/to/file
    var1="$var1"
    var2="$var2"
    EOF
    

    and to recreate your previous environment :

    source /path/to/file
    

    or

    . /path/to/file
    

    EXPLANATIONS

    • the place where to put the here-doc depends of your code, can be the last lines if you don’t have to save variables in loops by example
    • the place to put the source command is the top of your script after the shebang

    Help said :

    $ LANG=C help source
    

    source: source filename [arguments]
    Execute commands from a file in the current shell.

    Read and execute commands from FILENAME in the current shell.  The
    entries in $PATH are used to find the directory containing FILENAME.
    If any ARGUMENTS are supplied, they become the positional parameters
    when FILENAME is executed.
    
    Exit Status:
    Returns the status of the last command executed in FILENAME; fails if
    FILENAME cannot be read.
    

    NOTE

    if you want for some reasons to dynamically generate the files with pattern matching on variable names :

    • by suffix : printf '%q\n' $(set | grep "suffix=") > save_file
    • by prefix : printf '%q\n' $(set | grep "^prefix") > save_file

    Thanks gniourf_gniourf for printf trick.

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

Sidebar

Related Questions

Just wondering is it possible to build CLI app that can be run from
I'm wondering if it is possible to force an Open/Save dialog for an inline
Just toying with the SDK and I was wondering if possible a UITouch event
Just wondering if its possible to exclude large files or certian file types from
Possible Duplicate: Can i set property of Textview like justify? I'm writing an android
I'm wondering if it's possible to save a non-JPEG file (e.g. PNG) to the
Since it looks like recursive queries aren't possible in MySQL, I am wondering if
I was wondering ( if possible ) if there was a program/tool/utility that when
I am wondering if its possible to have a an (||)or or (&&)and operator
I was wondering if its possible to directly cast objects within a foreach loop.

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.