Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Suppose I have a bash shell script called Myscript.sh that need on argument as input.

But I want the content of the text file called text.txt to be that argument.

I have tried this but it does not work:

# cat text.txt | ./Myscript.sh

Do we have a way to do it?

share|improve this question
up vote 7 down vote accepted

Command substitution.

./Myscript.sh "$(cat text.txt)"
share|improve this answer

You can use pipe output as a shell script argument.

Try this method:

cat text.txt | xargs -I {} ./Myscript.sh {}
share|improve this answer

If you have more than one command in the file, consider using xargs or parallel, e.g.

xargs -d '\n' Myscript.sh < text.txt
parallel -j4 Myscript.sh < text.txt
share|improve this answer

Try,

 # cat comli.txt
 date
 who
 screen
 wget

 # cat comli.sh
 #!/bin/bash
 which $1

 # for i in `cat comli.txt` ; do ./comli.sh $i ; done

so you can enter the values one by one to comli.sh from comli.txt.

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.