How to create scripts that create another scripts

Posted by sfrj on Ask Ubuntu See other posts from Ask Ubuntu or by sfrj
Published on 2013-10-17T21:24:42Z Indexed on 2013/10/17 22:21 UTC
Read the original article Hit count: 437

Filed under:
|
|
|
|

I am writing an script that needs to generate another script that will be used to shutdown an appserver...

This is how my code looks like:

echo "STEP 8: CREATE STOP SCRIPT"
stopScriptContent="echo \"STOPING GLASSFISH PLEASE WAIT...\"\n
cd glassfish4/bin\n
chmod +x asadmin\n
./asadmin stop-domain\n
#In order to work it is required that the original folder of glassfish don't contain already any #project, otherwise, there will be a conflict\n"
${stopScriptContent} > stop.sh
chmod +x stop.sh

But it is not being created correctly, this is how the output stop.sh looks like:

"STOPING GLASSFISH PLEASE WAIT..."\n cd glassfish4/bin\n chmod +x asadmin\n ./asadmin stop-domain\n #In order to work it is required that the original folder of glassfish don't contain already any #project, otherwise, there will be a conflict\n

As you see, lots of things are wrong:

  • there is no echo command
  • is taking the \n literaly so there is no new line

My doubts are:

  • What is the correct way of making an .sh script create another .sh script.
  • What do you thing I am doing wrong?

© Ask Ubuntu or respective owner

Related posts about command-line

Related posts about server