lua スクリプトでモジュール ファイルを読み込んでいるときに、モジュール ファイルで指定された PATH 変数の値を読み込もうとしています。私はluaを初めて使用するため、luaの関数を使用してこれを実行できるかどうかはわかりません。
モジュール ファイル (netcdf) モジュール ファイルの一部のみを以下に示します -
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"
私はこのファイルを読んでいます。ユーザー/システムが使用している環境に関係なく使用できる PATH の 3 つの可能な組み合わせ値をすべて取得する方法はありますか?
- 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
私が書いたコードは行を読み取るだけですが、変数に値を配置して目的の PATH を取得することは困難です。
ルアコード -
-- 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
私が得た出力は、必要な関心のある行を示しているだけですが、PATH のすべての可能な値を取得することはまだ私の手の届かないところにあります。
-K