Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

3 Answers 3

up vote 5 down vote accepted

Command substitution.

./Myscript.sh "$(cat text.txt)"
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.