【发布时间】:2019-07-15 00:54:09
【问题描述】:
我试图在 bash 中运行一些代码。但我必须在循环中分配或设置变量。当我运行我的 .sh 时,出现错误:No command in line
以下是代码示例。
#! /bin/bash
newfile="/exp/exp/code"
bool=true
file="/exp/exp/newcode"
for i in {1..10}
do
declare $bool=false
$newfield =$file
$file=$i
done
【问题讨论】:
-
删除作业左侧的“$”。并删除“=”符号周围的所有空格。
-
顺便说一句,您不需要以这种方式在循环中“声明”。
-
shellcheck.net 。祝你好运。
标签: bash shell loops variables set