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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:56:01+00:00 2026-06-02T06:56:01+00:00

I want to include a data file in the batch script. Let me explain

  • 0

I want to “include” a data file in the batch script. Let me explain you as to how I would do it in Unix shell script so that there are no doubts as to what I am trying to achieve in batch script.

#!/bin/bash
. data.txt # Load a data file.

# Sourcing a file (dot-command) imports code into the script, appending to the script
# same effect as the #include directive in a C program).
# The net result is the same as if the "sourced" lines of code were physically present in the body of the script.
# This is useful in situations when multiple scripts use a common data file or function library.

# Now, reference some data from that file.
echo "variable1 (from data.txt) = $variable1"
echo "variable3 (from data.txt) = $variable3"

And this is the data.txt:

# This is a data file loaded by a script.
# Files of this type may contain variables, functions, etc.
# It may be loaded with a 'source' or '.' command by a shell script.
# Let's initialize some variables.
variable1=22
variable2=474
variable3=5
variable4=97
message1="Hello, how are you?"
message2="Enough for now. Goodbye."

In the batch script, my intention is to set the environment variables in data.txt and “source” that file in each of the batch script that I will create latter on. This will also help me make changes to the environment variables by just modifying one file (data.txt) instead of modifying multiple batch scripts. Any ideas?

  • 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-02T06:56:07+00:00Added an answer on June 2, 2026 at 6:56 am

    The easiest way to do that is by storing multiple SET commands in a data.bat file that then can be called by any batch script. For example, this is data.bat:

    rem This is a data file loaded by a script.
    rem Files of this type may contain variables and macros.
    rem It may be loaded with a CALL THISFILE command by a Batch script.
    rem Let's initialize some variables.
    set variable1=22
    set variable2=474
    set variable3=5
    set variable4=97
    set message1="Hello, how are you?"
    set message2="Enough for now. Goodbye."
    

    To “source” this data file in any script, use:

    call data.bat
    

    Adenddum: Way to “include” an auxiliary (library) file with functions.

    Use functions (subroutines) of the “included” file is not so direct as variables, but may be done. To do that in Batch, you need to physically insert the data.bat file into the original Batch file. Of course, this may be done with a text editor! But it may also be achieved in an automated way with the aid of a very simple Batch file called source.bat:

    @echo off
    rem Combine the Batch file given in first param with the library file
    copy %1+data.bat "%~N1_FULL.bat"
    rem And run the full version
    %~N1_FULL.bat%
    

    For example, BASE.BAT:

    @echo off
    call :Initialize
    echo variable1 (from data.bat) = %variable1%
    echo variable3 (from data.bat) = %variable%
    call :Display
    rem IMPORTANT! This file MUST end with GOTO :EOF!
    goto :EOF
    

    DATA.BAT:

    :Initialize
    set variable1=22
    set variable2=474
    set variable3=5
    set variable4=97
    exit /B
    
    :display
    echo Hello, how are you?
    echo Enough for now. Goodbye.
    exit /B
    

    You may even do source.bat more sophisticated, so it check the modification dates of the base and library files and create the _FULL version only when needed.

    I hope it helps…

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

Sidebar

Related Questions

I want to include Core Location and I'm trying to follow this tutorial: http://www.mobileorchard.com/hello-there-a-corelocation-tutorial/
i have a program that saves data to file and i want to put
I'm trying to append some data to a file, but in some cases want
I want to include a folder in a setup project so that when I
I want to include some dynamic part in the filename of the msi file
I want to include the last 2 files in my php file based on
I want to include a header file only if a certain function body is
I need to make an excel file which would fetch data from connection to
I have a test script, that generate txt file with answers. And have 2
I want to include a php file in one another and decode the JSON

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.