0

I have a property s3Path=s3a://myBucket in a file s3-apps.properties

Currently the path to a S3 is hardcoded in my bash script:

thePath="s3a://myBucket/myApp"

I want to get the property from the file instead and concatenate it with /myApp

So I'm getting path to the file like this:

file="/apps/properties/various/s3-apps.properties"

But how do I get the property and concatenate it to construct a path?

I guess that it should be something like this but it did not work for me:

thePath="s3a://{$file.s3Path}/myApp"

Non of the answers from the "Duplicate" helped me in understanding an solving my question. But the @cody answer below was correct and helped.

samba
  • 2,821
  • 6
  • 30
  • 85

1 Answers1

1

If you're using GNU grep, the following would work:

$ s3path=$(grep -Po '(?<=s3Path=).+$' "$file")
$ echo $s3path
s3a://myBucket
cody
  • 11,045
  • 3
  • 21
  • 36
  • is it a correct way to then construct the path like this? `thePath=$s3path/myApp` or do I need quotes here? – samba Nov 29 '18 at 16:03
  • @samba, quotes aren't needed on the right-hand of an assignment when none of the characters in the literal code (not the expansion results) would be otherwise misinterpreted as syntax. In a non-assignment context, you'd need them. – Charles Duffy Nov 29 '18 at 16:04
  • 1
    ...on the other hand, `echo $s3path` isn't great practice -- there *should* be quotes there, as described in [BashPitfalls #14](http://mywiki.wooledge.org/BashPitfalls#echo_.24foo). – Charles Duffy Nov 29 '18 at 16:05