首页 > 解决方案 > 尝试执行存储在变量中的命令时 bash 脚本出错

问题描述

我试图scanip.sh通过在另一个脚本 ( ) 中调用它来在后台 ( )中运行一个 bash 脚本stats.sh。这是stats.sh脚本:

#!/bin/bash

ifaces=("eth0" "eth1")
scripts_folder="~/comm"
conf_file="~/comm/conf"

scanip=(nohup "$scripts_folder"/scanip.sh "$conf_file" "${ifaces[0]}" &>/dev/null &)

"${scanip[@]}"

我将scanip命令(调用scanip.sh)作为数组存储在一个变量中,并尝试在最后一行执行它。但是每次我尝试运行时,输出都是:

./stats.sh: line 7: syntax error near unexpected token `&>'
./stats.sh: line 7: `scanip=(nohup "$scripts_folder"/scanip.sh "$conf_file" "${ifaces[0]}" &>/dev/null &)'

这里有什么问题?我应该如何构建这个脚本?

标签: bash

解决方案


推荐阅读