Glob的参数(带空格)

时间:2011-06-28 17:33:59

标签: bash arguments

继续我与争论和空间的斗争,考虑另外3个目录 目录和脚本:

Folder One
Folder Two
Folder Three
script

脚本如下:

#!/bin/bash
for i in $@
do
    echo $i
done

运行时:

./script *

我得到了这个输出:

Folder
One
Folder
Two
Folder
Three
script

是否有某种方法可以获得此输出:

Folder One
Folder Two
Folder Three
script

换句话说,不要在空格上分割$@参数?

1 个答案:

答案 0 :(得分:5)

试试这个:

#!/bin/bash
for i in "$@"
do
    echo $i
done