I am trying to read value of PATH variable given in a module file while reading the module file in a lua script. I am not sure whether this can be done using some function in lua, as I am pretty new to lua.
Module file (netcdf) only a part of the module file is given below -
set application netcdf
set version 4.1.1
set machine kgb
set app_base /sw/$machine/$application/$version
module-whatis "Sets up environment to use serial netcdf"
if [ module-info mode whatis ] {
break
}
#vvvvv If if not a library, remove this part vvvvv
if [ is-loaded intel ] {
set app_build "centos6.2_intel12"
} elseif [ is-loaded gcc ] {
set app_build "centos6.2_gnu4.4.6"
break
} elseif [ is-loaded pgi ] {
set app_build "centos6.2_pgi12.3"
break
} else {
puts stderr "You must have a programming environment loaded to use this module"
break
}
#^^^^^ If if not a library, remove this part ^^^^^
# This assumes something like --prefix=$SW_BLDDIR
set app_path $app_base/$app_build
setenv NETCDF_DIR "$app_path"
setenv NETCDF_INCLUDE "$app_path/include"
setenv NETCDF_LIB "$app_path/lib"
#setenv NETCDF_LINK "-I${FOO_INCLUDE} -L${FOO_LIB} -lfoo"
prepend-path PATH "$app_path/bin"
prepend-path LD_LIBRARY_PATH "$app_path/lib"
I am reading this file, is there any way to get all the three possible combination values of PATH that may be used irrespective of the environment user/system is having i.e.
- PATH = /sw/kgb/netcdf/4.1.1/centos6.2_intel12/bin
- PATH = /sw/kgb/netcdf/4.1.1/centos6.2_gnu4.4.6/bin
- PATH = /sw/kgb/netcdf/4.1.1/centos6.2_pgi12.3/bin
The code that I have written only reads the line but it is difficult to arrange the values in the variable and get the desired PATH.
Lua Code -
-- reading module file
local mfile = v.file
local lines = lines_from(mfile)
-- print all line numbers and their contents
for k ,v in pairs(lines)do
print('line['..k..']',v)
end
-- see if file exists
function file_exists(file)
local f = io.open(file,"rb")
if f then f:close() end
return f~= nil
end
-- get all lines from a file, returns an empty
-- list/table if the file does not exists
function lines_from(file)
if not file_exists(file) then return {} end
local lines = {}
for line in io.lines(file) do
if (string.match(line, 'set') or string.match(line,'prepend'))then
lines[#lines+1] = line
end
end
return lines
end
Output that I get just show the lines of interest that I need, but getting all the possible value of the PATH is still far away from my reach, any help would be appreciated!
-K