Sign up ×
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 have a script like this:

for i in *.TF; 
do
my command $i 
done

The problem is, each command line needs a same input (in this case: /PS) how can I do this? I have tested some methods like:

/PS | ./mybash.csh

It only works in first iteration. Just in case, /PS is some text (input) and I want feed it as input to each iteration of my command.

share|improve this question
    
Is /PS a program or some text? Do you want to feed that as input to each iteration of my command? –  roaima Mar 22 at 8:56
    
do you mean echo /PS? –  Skaperen Mar 22 at 10:34

2 Answers 2

simply write line below in a file call run.sh

for i in *.TF 
do
  my command "$i"  < /PS
done

then run

bash run.sh 

where

  • bash can replace by ksh
  • juste in case some files have whitespace you should enclose $i in quotes like "$i"
  • my command stand for a more complete command line (or you have a my programm in your $PATH)
  • this syntax in not a csh syntax by the way.
share|improve this answer
    
Thank you Archemar –  issa Mar 22 at 10:57

To also address the question "each command line needs a same input", in case that more or different commands are involved that should be fed from the same source, you can use yes:

yes "/PS" | my_script
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.