1

我想使用 bash 脚本在文本文件中输出值。我想以以下格式打印:

    Add item1 item2
    Add item3 item4
    Add item5 item6

Add 是一个返回值的可执行文件。我想将其保存在以下格式的文本文件中。我该怎么做?

   add1    add2    add3
   value1  value2  value3

value1、value2 和 value3 是返回值。

4

1 回答 1

1

我会尝试类似的东西

# This could probably be written as a loop,
# give more information about the items to add
names=("add1" "add2" "add3")
values=()
values+=( $(Add $item1 $item2) )
values+=( $(Add $item3 $item4) )
values+=( $(Add $item5 $item6) )

# Print each array on a single line, with
# individual items separated by tabs. The subshell
# localizes the change to IFS.
( IFS=$'\t'
  echo "${names[*]}"
  echo "${values[*]}"
)
于 2012-08-27T15:28:00.973 回答