Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 views
in Technique[技术] by (71.8m points)

shell - Unix Resolve sequence of variables stored in file

Given is a file named job.properties with below contents

version=current
rootDir=/a/b/c/repo
appPath=${rootDir}/${version}
workflowPath=${appPath}/workflow/test
oozie.wf.application.path=${workflowPath}/spark_scala/single_session_wf.xml

How to print resolved path using unix (#!/bin/ksh) or store it in variable?

Expected output :

/a/b/c/repo/current/workflow/test/spark_scala/single_session_wf.xml

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
source <(sed 's/=/="/;s/$/"/;s/^oozie.wf.application.path=/echo /' file)

Use sed to put double quotes around the entries after "=" and also change "oozie.wf.application.path=" to echo. Redirect the result back into source to get the desired result.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...