0

How can I append a string variable which I got through cut with next variable? In the file application.properties, I have value: myValue=/tmp/user/ I tried:

file=myfile.properties
path=$(cat application.properties | grep myValue=)
path2=$(echo $path | cut -d'=' -f 2- )
pathToFile=$path2$file

But output is only: myfile.properties. I need /tmp/user/myfile.properties

Thank you for your help.

donjuedo
  • 2,475
  • 18
  • 28
user3468921
  • 561
  • 2
  • 8
  • 26
  • Seems your path2 variable's value may be empty(just test it by assigning a test value and pathToFile=$path2$file should work), so better if you could let us know sample Input_file and expected output too. – RavinderSingh13 Mar 13 '17 at 14:39
  • *nod*. Running `bash -x yourscript` would be helpful for detecting where things are first behaving in an unexpected manner. – Charles Duffy Mar 13 '17 at 14:39
  • Path2 always contains value. it was tested, Input file (application.properties) have format: **variable=value** ( For example: myValue=/tmp/user/) next input is file ( these value is obtained from folder) For example: myfile.properies **Output: tmp/user/myfile.properies** I running bash yourscrip.sh – user3468921 Mar 13 '17 at 14:55

1 Answers1

0

Don't use cut for this at all: The shell's built-in string manipulation can do this trimming for you. (And don't use cat: It's more efficient to have grep read straight from the file than to have it reading from a separate process that then writes to a FIFO).

file=myfile.properies
path=$(grep myValue= <application.properties)
pathToFile=${path#*=}${file}
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441