CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
help with shell script


New User

Jul 26, 2012, 1:32 AM

Post #1 of 7 (2754 views)
help with shell script Can't Post

Hi everyone, I apologize in advance if this is not the appropriate place to ask for this kind of help.

I am very, very new to perl and scripting in general and I am trying to set up a shell script that will allow me to run a series of commands that each rely on the output of the previous after specifying a directory to put the results into (/mypath/user_input_directory/ below).

The first command takes the input files in the working directory and parses them into specific folders (already created):

perl -fork1 -UQseqToTagCountPlugin w mypath/user_input_directory/ -e ApeKI -endPlugin -runfork1

and the second takes the results in that directory and further processes them:

perl -fork1 -UMergeTaxaTagCountPlugin -w mypath/user_input_directory/ -c 5 -endPlugin -runfork1

it continues this way for several more perl commands:

perl -fork1 -UTagCountToTagPairPlugin -w mypath/user_input_directory/ -e 0.03 -endPlugin -runfork1


Is there an easy way to automate all of these individual commands with an input for the working directory from the user. I ask because each step takes quite a while and it would be nice just to hit run and go.

Thank you so much in advance for any help that anyone may provide, it is much appreciated!



Jul 26, 2012, 5:56 AM

Post #2 of 7 (2743 views)
Re: [sooper] help with shell script [In reply to] Can't Post

I assume that you are unwilling to change the script to do the entire job. Although all-perl solutions are possible, I agree that a shell script is your easiest solution. No one can offer much more help without knowing your operating system (and shell).

One other solution is a perl program which would consist of almost nothing but calls to system (refer perldoc -f system). Each call would execute one of your steps. If this is intended as production software, you should add error processing.
Good Luck,


Jul 27, 2012, 4:12 AM

Post #3 of 7 (2736 views)
Re: [sooper] help with shell script [In reply to] Can't Post

You really should post this in a forum for Shell scripts, but....

I would pass the working directory as parameter to the shell script (instead of asking the user for input), because this will make your script useful in a wider context.

You didn't point out, which Shell you are going to use, but from the way you write your pathes, I assume that you are on a Unix like system. Here is an example for zsh (it would work likewise with bash and, AFIK, with ksh, ash and Bourne Shell):

#!/bin/zsh -f 
# Ensure that the user supplied a directory
: ${1?Parameter missing - must be user directory}
perl -fork1 -UQseqToTagCountPlugin w mypath/$1 -e ApeKI -endPlugin -runfork1

Of course you would have to adapt the #! line according to your system.

New User

Jul 30, 2012, 11:02 PM

Post #4 of 7 (2653 views)
Re: [rovf] help with shell script [In reply to] Can't Post

Thank you for your suggestions. Yes I am using a unix shell (ubuntu).

I will give this a shot.

Thank you again!!!

Veteran / Moderator

Jul 31, 2012, 3:05 AM

Post #5 of 7 (2645 views)
Re: [sooper] help with shell script [In reply to] Can't Post

I think that using the unix shell pipe fonctionnality ("|") is the simple way, it takes the output of the first program and feeds it as input for the second one.

Something like at the unix command line :

perl input_file_progr1.txt | perl

A few points to be noted however:

- must write to standard output, not to a file (i.e. you print without a file handla, as if you wanted to print to the screen)

- must read from standard input (i.e. you read the data with something like "while (my $line = <>), juste as if you were waiting a user to enter data).

- You will not have the intermediate file (the result of

The alternative if you prefer to have an intermediate file, you can do this at the Unix prompt:

perl input_file_progr1.txt > output_file_progr2.txt ; perl output_file_progr2.txt

The semi-colon (;) in this command will guarantee that is completed before starting


Jul 31, 2012, 8:12 PM

Post #6 of 7 (2628 views)
Re: [Laurent_R] help with shell script [In reply to] Can't Post

I would prefer a the second method.
Having a new main program which is going to call these command one by one.

New User

Aug 28, 2012, 12:20 AM

Post #7 of 7 (2012 views)
Re: [rovf] help with shell script [In reply to] Can't Post

Thank you again for your help. Your suggestion worked perfectly.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives