Linux Tips and Tricks

Linux Tips and Tricks

Dot or Source Operator – Unix/Linux

May3

Dot or Source Operator

Read and execute commands from the filename argument in the current shell context.

A period `.’ is a synonym for `source’

Create a file called test.cfg and enter the below contents

1
2
3
4
5
$ cat test.cfg
hostname=mymachine.com
password=password
ftpname=abc
ftppassword=xyz

 

1
2
3
4
5
$ . test.cfg
 
or
 
$ source test.cfg

Accessing the Values

1
2
3
4
5
6
7
8
9
10
11
$ echo $hostname
mymachine.com
 
$ echo $password
password
 
$ echo $ftpname
abc
 
$ echo $ftppassword
xyz

Accessing the Function from the file

1
2
3
4
5
$ cat test.func
function abc
(
    echo "I am inside the abc function"
)

 

1
2
3
4
5
$ . test.func
 
or
 
$ source test.func

 

1
2
3
#Calling the function abc
$ abc
I am inside the abc function
posted under Uncategorized

Email will not be published

Website example

Your Comment:


Recent Comments

    Categories