如何从bash / shell脚本中的java属性文件提取值并存储到变量中,然后将cd存储到该变量中 [英] How to extract values from a java properties files in a bash/shell script and store in a variable and cd to that variable

查看:208
本文介绍了如何从bash / shell脚本中的java属性文件提取值并存储到变量中,然后将cd存储到该变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个config.properties文件,其中包含一个像 ouputdir = / data1 / testdata / output 这样的路径。我能够在shell中提取这些文件并将此路径存储在一个变量中。虽然我正在尝试将目录更改为此路径,但出现如下错误:没有此文件或目录/ data1 / testdata / output ,但存在此路径。 p>

我试过的是:

  configPath = / data1 / testdata.config .properties 
my_value = $(grep outputdir $ configPath | awk -F ='{print $ 2}')
echo $ my_value
cd $ my_value

由此我能够在my_value变量中打印路径。但我无法将目录更改为$ my_value.can。有人告诉我什么是这里错了,我怎么能改变目录到这个变量。

解决方案

你应该有什么工作。检查显而易见的,该目录是拼写正确的,并存在。



值得一提的是,您可以将grep和awk命令合并为一个:

  my_value = $(awk -F ='$ 1 ==outputdir{print $ 2}')


I have a config.properties file which contains a path like ouputdir=/data1/testdata/output. I am able to extract these in shell and store this path in a variable. While I am trying to change directory to this path, I am getting error something like: No such file or directory/data1/testdata/output, thouth this path exists.

What I tried is:

configPath=/data1/testdata.config.properties
my_value=$(grep outputdir $configPath|  awk -F= '{print $2}')
echo $my_value
cd $my_value

by this I am able to print the path in my_value variable.but I am not able to change directory to $my_value.can anybody tell me what is wrong here and how can I change directory to this variable.

解决方案

What you have should work. Check the obvious, that the directory is spelled right and does exist.

For what it's worth, you could combine the grep and awk commands into one:

my_value=$(awk -F= '$1=="outputdir" {print $2}')

这篇关于如何从bash / shell脚本中的java属性文件提取值并存储到变量中,然后将cd存储到该变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆