shell - create a path from lines in a file on the unix command line -


i want build basic java class path in bash script.

this command works out jar files go in path:

find ~/jars | grep \.jar$ 

this lists jar files want on path, 1 per line.

how can join these lines on 1 line, separated : , put variable can use in script when invoke java?

e.g.:

jars=`find ~/jars | grep \.jar$` #### somehow make jars 1 line : between entries java -cp $jars ... 

you can pipe , sed change new line ,:

sed ':a;n;$!ba;s/\n/:/g' 

all together,

find ~/jars | grep \.jar$ | sed ':a;n;$!ba;s/\n/:/g' 

you can tr, although leaves trailing colon (glenn jackman comment):

find ~/jars | grep \.jar$ | tr '\n' ':' 

based on sed: how can replace newline (\n)?


Comments