Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I want to use a directory name as a parameter for a pre-made script. Then the output goes into a newly made file in the home directory. It involves pipe/redirection. How do I do that?

read dir
$dir > script > outputfile
share|improve this question
    
ok I figured out the syntax something like: script<$dir >|outputfile but it doesn't seem to accept directory as a parameter unless I entered it wrong. and how can I choose home directory as the location for outputfile? –  asura Sep 28 '14 at 5:34
    
you have to use script < $dir > ~/outputFile. Here ~ is the home directory. –  user2555595 Sep 28 '14 at 6:07

1 Answer 1

If you want to use the directory name as-is in your script, pass it as a parameter:

script $dir > outputfile

You can't redirect a directory to a script, what do you expect to see as the input? The name? The names of the directory entries? The contents of the directory entries? etc.

I'm assuming as you're writing scripts, you know how to process a parameter. What exactly are you trying to accomplish? Show the script. It's not a homework assignment, is it?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.