Jump to content

Making a shell script that generates a perl file?


Recommended Posts

it would be helpful if you can give more details on what exactly (specific task) you want to do so our scripting nut and apostles can take a crack at that.

 

from a newbie pov, creating a helloworld perl script from bash would be just a direct mapping something like this

 

 #!/bin/bash

  file=hello.pl
  echo "#!/bin/perl" > $file
  echo "print hello" >> $file
  chmod +x $file

 

assuming "print hello" is how you print strings in perl. as you can see it takes twice number of lines to do it that way but would be useful if it is used in a scenario wherein certain conditions are iterated to create a meaningful set of scripts.

 

we can wait for gAru or somebody of his scripting tendencies to drop by to give you something that will automatically whiz past by my head. gAru has that tendency to show how nutty scripting can be. :twisted:

 

ciao!

Link to comment
Share on other sites

This is cleaner:

#!/bin/bash

file=hello.pl
echo "#!/bin/perl" > $file
echo "print \"hello!\n\"" >> $file

 

You were close ramfree, but perl's print needs the quotes around hello, so to insert them, you have to put escaped quotes -> \" Plus the \n (newline) makes it return you back to a prompt on a (guess what) new line. :P

 

Edit: This is probably even better:

#!/bin/bash

file=hello.pl
cat > $file <<EOM
#!/bin/perl

print "hello\n";
exit;
EOM
chmod +x $file

 

 

Edit #2: Hmmmm. From the 'time' command, the first one actually is twice as fast .01 seconds as opposed to .02 seconds. Also, the first one has 332 minor pagefaults and the second has 712 minor pagefaults (whatever that means). :D

Edited by Steve Scrimpshire
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...