2

I want to take a word as input and creating consecutive directories using the letters of this word in unix shell. I tried sed, awk and fold commands but did not obtaiın any useful result. Any advice?

For example: If input is hello, it should create h/e/l/l/o directories as one inside another. In other words, h will be the top directory and o will be the deepest subdirectory.

4

2 に答える 2

2

これは、Bourne 互換シェルでうまくいくはずです。

$ mkdir -p $(echo foobar | sed 's:\(.\):\1/:g')
$ find f
f
f/o
f/o/o
f/o/o/b
f/o/o/b/a
f/o/o/b/a/r

の最初のペアによって一致したテキストへの後方参照\1であることに注意してください。また、展開結果は-- ですが、末尾のスラッシュを無視していることにも注意してください。\(...\)mkdir -p f/o/o/b/a/r/mkdir

于 2013-04-26T20:14:54.800 に答える