Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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

I am using this code to print all open files in the specified changelist.

while read line; do
    echo "$line"
done < `p4 opened -c $changelist`

However, the line also gets executed and I get following error:

./do.sh: line 7: //perforce/a.js#24 - edit change 353 (text) by user1: No such file or directory

My required output is:

//perforce/a.js#24 - edit change 353 (text) by user1
share|improve this question
up vote 3 down vote accepted

With , and ProcessSubstitution :

while IFS= read -r line; do
    echo "$line"
done < <(p4 opened -c $changelist)

See http://mywiki.wooledge.org/ProcessSubstitution and http://mywiki.wooledge.org/BashFAQ/024

If not using one of these shells (like Joseph R. said in comments), use a simple pipe :

p4 opened -c $changelist | while IFS= read -r line; do
    echo "$line"
share|improve this answer
Awesome turnaround time! It works. Can you give me an idea of what "< <" is called? – Asad Iqbal Oct 29 '13 at 20:27
Btw, this needs a #!/bin/bash instead of #!/bin/sh – Asad Iqbal Oct 29 '13 at 20:27
While, it's true that process substitution is not standard sh syntax, it originates in the Korn Shell, not bash (though it is also available in bash and zsh). – Stéphane Chazelas Oct 29 '13 at 21:28
You can also use a simple pipe: p4 opened -c $changelist | while ... and avoid the portability issues that come with process substitution. – Joseph R. Oct 30 '13 at 22:24

Your Answer


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.