How to extract values from a java properties files in a bash/shell script and store in a variable and cd to that variable

后端 未结 2 1303
走了就别回头了
走了就别回头了 2021-01-14 18:37

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 variabl

相关标签:
2条回答
  • 2021-01-14 18:42

    Does your properties file have windows CRLF line endings? your script may think the directory is /data1/testdata/output^M with the trailing carriage return.

    sed -n '/^outputdir=/{s///; s/\r$//; p; q}' properties.file
    
    0 讨论(0)
  • 2021-01-14 18:46

    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}')
    
    0 讨论(0)
提交回复
热议问题