neocytrix Posted April 16, 2004 Report Share Posted April 16, 2004 Hello, I have a quick question, how would I make a shell script that, when ran would make a perl file. Exampe: If I wanted to make a shell script that would make a perl file which said "hello" when ran. Thanks! -Neocytrix Quote Link to comment Share on other sites More sharing options...
ramfree17 Posted April 16, 2004 Report Share Posted April 16, 2004 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. ciao! Quote Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted April 16, 2004 Report Share Posted April 16, 2004 (edited) 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 April 16, 2004 by Steve Scrimpshire Quote Link to comment Share on other sites More sharing options...
ramfree17 Posted April 16, 2004 Report Share Posted April 16, 2004 i rest my case. ciao! Quote Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted April 17, 2004 Report Share Posted April 17, 2004 I'm sure aru can do it with a one-liner, though. :P Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.