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 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
add comment

1 Answer 1

up vote 2 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"
done
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
1  
3  
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
1  
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
add comment

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.