FreeKB - Linux Commands source (export variable)
Linux Commands - source (export variable)

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

#!/bin/bash
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 de1d0 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |