Assign results of globbing to a variable in Bash

前端 未结 4 1648
孤独总比滥情好
孤独总比滥情好 2021-01-01 09:30

My colleague, Ryan, came to me with a bug in his Bash script, and I identified the problem with this test:

$ mkdir ryan
$ mkdir ryan/smells-bad
$ FOO=ryan/sm         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-01 09:43

    Consider

    for dir in $FOO; do
        touch "$dir/rotten_eggs"
    done
    

    Note that this will touch multiple files if the glob pattern matches more than one pathname.

提交回复
热议问题