如何在shell脚本中提供输入列表?

时间:2015-02-17 14:23:36

标签: linux shell svn

我需要在Shell脚本中提供输入列表并读取它们并迭代并为每个文件夹执行'svn update',如下所示:

    echo "Please give the list of folders to be updated:"
    read $list
    for name in ${list[@]} do
          svn update $name
    done

如何通过shell脚本实现此功能。

谢谢和问候,

拉​​加

2 个答案:

答案 0 :(得分:1)

如果您尝试将值读入数组,请使用:read -a

read -a list -p "Please give the list of folders to be updated: "

for name in "${list[@]}"; do
   svn update "$name"
done

否则就这样使用:

read -p "Please give the list of folders to be updated: " list

for name in $list; do
   svn update "$name"
done

但请记住,您的文件夹名称不应包含空格或换行符。

答案 1 :(得分:0)

#!/bin/bash

echo "Please give the list of folders to be updated:"
read list $*
for name in "${list[@]}"; do
    svn update "${name}"
done