36、脚本编程中的参数、循环与数据处理

脚本编程中的参数、循环与数据处理

1. 位置参数

位置参数在脚本编程中是非常重要的概念,它们允许我们在执行脚本时传递参数。以下是不同形式的位置参数及其结果:
| 形式 | 结果 |
| ---- | ---- |
|$1 = word
$2 = words
$3 = with
$4 = spaces| 原始位置参数 |
|"$*"|$1 = word words with spaces
$2 =
$3 =
$4 =|
|$@|$1 = word
$2 = words
$3 = with
$4 = spaces|
|"$@"|$1 = word
$2 = words with spaces
$3 =
$4 =|

从上述结果可以看出,"$@"是最有用的,因为它能保留每个位置参数的完整性。在大多数情况下,为了