Export variables in bash shell script using the SOURCE command in Linux

Home > Search > Linux commands

Let's consider a BASH shell script named example.sh that contains a variable named HW that contains the text Hello World

HW="Hello World"


There will be no output when issuing the echo $hw command.

[user1@server1 ~]# echo $hw


The source command is used to tell your shell to use your example.sh script. Instead of using the word source, just a single period can be used as well.

[user1@server1 ~]# source example.sh
[user1@server1 ~]# . example.sh


Now, echo $hw will produce Hello World.

[user1@server1 ~]# echo $hw
Hello World



Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter in the box below so that we can be sure you are a human.