how can I improve this algorithm in bash
basically I have a directory with files, and I want to output current file, previous file, next file. So here's my algorithm
Code:
for ((i=0; i<$total; i++)); do |
Maybe you can avoid superfluous assignments:
Code:
for ((i=0; i<$total; i++)) |
If you are going to use (()) for the for statement, why not use them for the rest of your arithmetic expressions?
Code:
for ((i=0; i < total; i++)); do I am curious to the output when i = 0, ie nextfile is not calculated, so strictly speaking, unless total is 1, this should have a value. Lastly, when the output shows a single file name (or any for that matter), how do you know which position this name is in? This perhaps picky, but if the script is not just for you (or you run it in a months time and forget) it may be tricky for a user to tell exactly what they are seeing without any labels ... just a thought ;) |
Quote:
So if you look at my script above, instead of echo to stdout I would call another function that has some html code and create a page for every picture with links to previous and next. Hope it makes sence. |
Well whilst this may be an improvement on the current code, I think colucix has presented the best option, ie use the array you have created which removes most if not all the if / else requirements
|
All times are GMT -5. The time now is 12:54 AM. |