bash - 修复 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 `>'
这是为什么?我该如何解决这个问题?
解决方案
你少了两杯半可乐。这是固定版本:
for i in 1 2 3; do echo This is a sample text > sample-$i.txt; done
推荐阅读
- nim-lang - 从图像文件创建颜色直方图
- python - 如何将 UTF-16-LE txt 文件转换为 ANSI txt 文件并删除 PYTHON 中的标头?
- html - 如何将 div 的内容围绕特定元素居中?
- android - 滚动视图不起作用?适用于设计预览,但不适用于仿真器/设备
- javascript - 预加载时如何使新窗口出现加载指示器?
- reactjs - 如何在 React Native 中设置键盘上方的 TextInput 字段
- javascript - 如何在 vue 库中使用 VI18n
- elasticsearch - Elasticsearch - 没有应用别名过滤器
- javascript - Node.js:将管道与流一起使用时的错误处理
- c++ - 从 vtkImageData 加载 vtkDICOMReader