I am using tcsh. I want to output:

mkdir dir1 dir2 dir3 dir4

Where of course the maximum number of dirs is variable. The point is they contain the incrementing variable from a loop in their names. I have a feeling I should use xargs. I just want to be able to use a simple loop, and do it all in one line if possible. Is this possible? My feeling is it will be something like:

loop here | xargs mkdir

but I am just not able to make my syntax work.

edit: I figured out how to do it with multiple lines of input. Anyone know how to make the following into a single line input?

for i in {1..5}
do
echo -n " dir$i"
done \
| xargs mkdir
有帮助吗?

解决方案

Code:

foreach a ( `seq 1 1 10` )
  mkdir dir$a
end

or

seq -f 'dir%.0f' -s ' ' 1 1 10 | xargs mkdir
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top