How do I split a String in CSH?

后端 未结 3 1515
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-17 21:09

For example, I want to split \"one,two,three\" with comma as delimiter and use a loop to process the resulted three substring separately.

3条回答
  •  被撕碎了的回忆
    2021-01-17 21:28

    For example:

    set s = "one,two,three"
    set words = `echo $s:q | sed 's/,/ /g'`
    foreach word ($words:q)
        echo $word:q
    end
    

    But consider whether csh is the right tool for whatever job you're doing:

    http://www.bmsc.washington.edu/people/merritt/text/cshbad.txt

提交回复
热议问题