Syntax for a single-line Bash infinite while loop

前端 未结 13 1379
长情又很酷
长情又很酷 2020-11-29 14:18

I am having trouble coming up with the right combination of semicolons and/or braces. I\'d like to do this, but as a one-liner from the command line:

while [         


        
13条回答
  •  [愿得一人]
    2020-11-29 14:49

    If I can give two practical examples (with a bit of "emotion").

    This writes the name of all files ended with ".jpg" in the folder "img":

    for f in *; do if [ "${f#*.}" == 'jpg' ]; then echo $f; fi; done
    

    This deletes them:

    for f in *; do if [ "${f#*.}" == 'jpg' ]; then rm -r $f; fi; done
    

    Just trying to contribute.

提交回复
热议问题