Generating two bash arguments from 'ls'
Dear Forum
Say I have a directory containing the following files. Code:
1-res-opt-I189N-0001.pdb Code:
for i in *.pdb How do I do that? Thanks for any hints. |
If you have bash 4 you can use extended brace expansion with zero-padded numbers:
Code:
for i in {0001..10} Code:
for i in {1..10} |
more than helpful. Thanks.
|
For the record, this is what your original code does...
Code:
for i in *.pdb Inside the loop you have a line with brace expansions inserted. These get expanded before execution, so you get a single command that looks like this: Code:
python my_script.py 1-res-opt-I189N-001.pdb 1-res-opt-I189N-002.pdb 1-res-opt-I189N-003.pdb 1-res-opt-I189N-004.pdb 1-res-opt-I189N-005.pdb 1-res-opt-I189N-006.pdb 1-res-opt-I189N-007.pdb 1-res-opt-I189N-008.pdb 1-res-opt-I189N-009.pdb 1-res-opt-I189N-0010.pdb 3-res-opt-I189N-001.pdb 3-res-opt-I189N-002.pdb 3-res-opt-I189N-003.pdb 3-res-opt-I189N-004.pdb 3-res-opt-I189N-005.pdb 3-res-opt-I189N-006.pdb 3-res-opt-I189N-007.pdb 3-res-opt-I189N-008.pdb 3-res-opt-I189N-009.pdb 3-res-opt-I189N-0010.pdb As colucix demonstrated, generate the list of files you want to use (or in this case a sequence of numbers that can be used inside the loop to match filenames) first, then feed that to the for loop and use the variable set by it to access them one at a time. By the way, for zero padding in bash 3, you could also simply do something like this: Code:
for i in 000{1..9} 0010 ; do http://mywiki.wooledge.org/BashFAQ/018 |
@david the h.:
thanks a lot. very informative post. kind regards |
All times are GMT -5. The time now is 02:01 PM. |