bash - Generate multiline file with Make -


i want create multiline file make, having exact content:

#!/bin/bash  if [ "$java_home" = "" ]; echo "please set java_home"; exit 1; fi export config_vars=$( cat <<eof  -dmapred.job.tracker=$jt eof )  ${hadoop_home}/bin/hadoop $1 $hadoop_config_vars ${*:2} 2>&1 | grep -v slf4j 

how can tell make output file exact content somewhere?

i tried this:

define script_content #!/bin/bash  if [ "$java_home" = "" ]; echo "please set java_home"; exit 1; fi export config_vars=$( cat <<eof  -dmapred.job.tracker=$jt eof )  ${hadoop_home}/bin/hadoop $1 $hadoop_config_vars ${*:2} 2>&1 | grep -v slf4j endef export script_content bin/script:     @echo "$$script_content" > bin/script 

this paricular solution 1) wipes $ , first char after $-es , 2) ugly because definition should happen outside of particular target it's needed :(

i tried this:

bin/script:     @echo '     #!/bin/bash      if [ "$java_home" = "" ]; echo "please set java_home"; exit 1; fi     export config_vars=$( cat <<eof      -dmapred.job.tracker=$jt     eof     )      ${hadoop_home}/bin/hadoop $1 $hadoop_config_vars ${*:2} 2>&1 | grep -v slf4j     ' > bin/script 

this returns error when in make, works outside of make...

any suggestion welcome!

with this magnificent answer, cooked following.

# https://stackoverflow.com/a/8316519/874188 define \n   endef define script_content #!/bin/bash  if [ "$$java_home" = "" ]; echo "please set java_home"; exit 1; fi export config_vars=$$( cat <<eof  -dmapred.job.tracker=$$jt eof )  $${hadoop_home}/bin/hadoop $$1 $$hadoop_config_vars $${*:2} 2>&1 | grep -v slf4j endef  bin/script:     echo '$(subst $(\n),\n,$(script_content))' >$@ 

when testing, found needed have semicolon @ end of echo line when didn't have redirection. can speculate there built-in echo gets invoked when there no shell metacharacters in command line?

also, notice definition cannot contain single quotes, , dollar signs have doubled. maybe 1 or other of these restrictions removed; unsuccessful, didn't spend time or effort.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -