Globbing/pathname expansion with colon as separator

前端 未结 8 1355
鱼传尺愫
鱼传尺愫 2020-12-28 16:23

How can I convert a string containing glob characters such as

/var/lib/gems/*/bin

into a colon-separated string of filenames (i.e. PATH com

8条回答
  •  一个人的身影
    2020-12-28 16:46

    This should do it for you:

    dirs=(/var/lib/gems/*/bin)    # put filenames (dirnames) in an array
    saveIFS=$IFS IFS=':'          # set the Internal Field Separator to the desired delimiter
    dirs=("${dirs[*]}")           # convert the array to a scalar with the new delimiter
    IFS=$saveIFS                  # restore IFS
    

提交回复
热议问题