首页 > 解决方案 > 修复 bash:意外标记 `>' 附近的语法错误

问题描述

我有一个 bash 语法错误问题。我正在编写一个脚本来在文件中插入信息而不像这样打开文件

for i in 1 2 3 do echo This is a sample text > sample-$i.txt done

但它给出了以下错误

bash: syntax error near unexpected token `>'

这是为什么?我该如何解决这个问题?

标签: bash

解决方案


你少了两杯半可乐。这是固定版本:

for i in 1 2 3; do echo This is a sample text > sample-$i.txt; done

推荐阅读