如何将一行输入转换为shell中的多行

时间:2018-02-01 11:50:37

标签: shell unix

我使用的shell脚本包含多行IP的1行输入

脚本输入:

./part1.sh 10.10.11 10.10.12 10.10.13
shell脚本中的

export Master="$1 $2 $3"

the output is -- >10.10.11 10.10.12 10.10.13

我想在脚本中使用它

  

10.10.11

     

12年10月10日

     

10.10.13

我们如何在脚本中转换它?

1 个答案:

答案 0 :(得分:0)

例如使用bash:

$ cat foo.sh
#!/bin/bash

declare -a ips=( "$@" )

for ip in "${ips[@]}"
do
  echo $ip
done

运行它:

$ bash foo.sh 10.10.11 10.10.12 10.10.13
10.10.11
10.10.12
10.10.13