Magazine

Sharing the Data with Many Functions in Linux Bash Script

Posted on the 25 April 2021 by Satish Kumar @satish_kumar86

We can create variablesthatmay contain strings or numerical values. These global variables can be accessed by all the functions inside a script.

A simple script calledfunction_11.shwith functions is as follows:

function_11.sh

#!/bin/bash 
# We will define variable temp for sharing data with function 
temp="/temp/filename" 
 
remove_file() 
{ 
  echo "removing file $temp..." 
} 
remove_file 

Test the script as follows:

$ chmod +x function_11.sh
$ ./function_11.sh

This should produce the following output:

Output:

removing file /temp/filename...

Back to Featured Articles on Logo Paperblog