bash - 来自“学习 Bash Shell,第 3 版”的示例练习问题。[纽汉,卡梅伦]
问题描述
来自第 2 章。“学习 Bash Shell”第 3 版,“fc 命令”:
“请记住,fc 在您编辑命令后实际上会运行这些命令。因此,最后命名的选择可能很危险。当您退出编辑器时,bash 将尝试执行您指定的范围内的所有命令。如果您已输入任何多行结构(就像我们将在第 5 章中介绍的那样),结果可能更加危险。尽管这些似乎是生成“即时 shell 程序”的有效方法,但更好的策略是直接输出fc -ln 对文件使用相同的参数;然后编辑该文件并在您对它们满意时执行命令:
$ fc -l cp > lastcommands
$ vi lastcommands
$ source lastcommands
在这种情况下,当您离开编辑器时,shell 将不会尝试执行该文件!”
我做了:
$ fc -l
这给出了输出:
1 回声测试1
2 回声测试2
3 回声测试3
4 回声测试4
所以我尝试了:
$ fc -l cp > lastcommands
但得到:
-bash: fc: history specification out of range
想知道为什么我得到超出范围的错误。文件“lastcommands”已创建,但为空。
解决方案
我试过了:
$ fc -l cp > lastcommands
但得到:
-bash: fc: history specification out of range
审查help fc
(截断)
$ help fc
fc: fc [-e ename] [-lnr] [first] [last]
Display or execute commands from the history list.
… FIRST can be a
string, which means the most recent command beginning with that
string.
…
-l list lines instead of editing
FIRST
你作为 string传递cp
。您的历史记录中似乎没有以 . 开头的命令cp
。
尝试使用绝对不会成为 bash 历史记录中的命令的唯一字符串:
fc -l NOTINYOURHISTORY
你会得到同样的错误。
推荐阅读
- java - 生成特定的 XMLGregorianCalendar 格式并将其转换为规范化
- javascript - 我的应用程序未在颤振中连接到 socketIO 后端服务器
- android - 为什么我的应用可以与应用操作测试工具一起使用,但在 Play 商店发布时却不行?
- java - 如何从弹出窗口类更改片段中的 ImageView?
- python - 旋转矩阵反转 Z 轴
- python - VPython 轨道运动窃听
- typescript - Typescript 对象的类型未知,firebase 函数
- python - 有没有办法调整 Pandas 滚动相关函数来计算数据帧的格兰杰因果关系的滚动 P 值?
- android - 尽管使用了我在 stackoverflow&android 开发人员上找到的所有解决方案,但 Android 服务仍被破坏
- next.js - JIT tailwindcss 在 bg-[] 中使用变量不渲染颜色