• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

Bash Variables

June 27, 2020

Here’s how to read Bash variables from another file.

Contents of config.sh

#!/bin/bash
var1='thisisvariableone'
var2='thisisvariabletwo'

#!/bin/bash var1='thisisvariableone' var2='thisisvariabletwo'

Call config.sh from another script.

#!/bin/bash
source config.sh
echo var1
echo var2

#!/bin/bash source config.sh echo var1 echo var2

This is extremely helpful if you have multiple scripts using a common variable. You just to update one file instead of multiple files. All the other scripts will read and pick up the same variables from a config file. You can use this to setup your global variables.

Filed Under: Linux Tagged With: another, bash, file, source, variable

Search This Website

Subscribe Via Email

  • Home
  • About
  • Archives

Copyright © 2023