我在玩Turtle,我遇到了以下問題。如何grep海龜的ls結果
我想這樣做(帶殼)
ls | grep 'foo'
使用龜我的嘗試是
grep (prefix "foo") (ls ".") & view
,但我得到了以下信息
Couldn't match type ‘Turtle.FilePath’ with ‘Text’
Expected type: Shell Text
Actual type: Shell Turtle.FilePath
In the second argument of ‘grep’, namely ‘(ls ".")’
In the first argument of ‘(&)’, namely
‘grep (prefix "foo") (ls ".")’
我明白ls
回報FilePath
而grep
適用於Text
,那我該怎麼辦?
更新
有明顯這涉及到來回轉換,從FilePath
到Text
解決方案。這超出了我期望的類似shell的程序的簡單性。
有人提到了find
函數,它可以以某種方式解決問題。 但是find
相當於find
shell函數,我只是想做ls | grep "foo"
。我並沒有試圖解決現實生活中的問題(如果是的話,我會轉而使用bash),但是試圖結合簡單的磚塊,就像我在bash中做的那樣。不幸的是,它似乎並沒有在龜磚是易:-(結合起來。
+1不壞,但能夠解決一半的問題。假設我想將選定的文件移動到某處,然後我需要將它們轉換回'FilePath'。 – mb14
'repr'在ghci中有效,但我無法在您提供的鏈接上找到它。 – mb14
@ mb14我編輯了答案以包含正確的鏈接。還要注意''repr = format w''格式描述[這裏](https://hackage.haskell.org/package/turtle-1.0.0/docs/Turtle-Format.html#v:format)。 – Bakuriu