AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 684765
Accepted
Luca Schulz
Luca Schulz
Asked: 2022-01-03 16:24:57 +0800 CST2022-01-03 16:24:57 +0800 CST 2022-01-03 16:24:57 +0800 CST

如何替换最新命令的第一个参数?

  • 772

如果我像这样在终端中运行命令

$ tyop --count 3 --exact haveibeenpwned

并且命令返回错误代码,例如

command not found: tyop,

如何重新运行最后一个命令,将命令行参数保留为--count 3 --exact haveibeenpwned另一个命令名称(例如typo,而不是tyop)?

$ typo --count 3 --exact haveibeenpwned

如果可能的话,我正在寻找快捷方式或 shell 函数,例如!!or !^。

shell command-line
  • 3 3 个回答
  • 623 Views

3 个回答

  • Voted
  1. Best Answer
    Quasímodo
    2022-01-03T17:08:51+08:002022-01-03T17:08:51+08:00
    typo !*
    

    来自man bash:

    Word Designators
       Word designators are used to select desired words from the event.  A :
       separates the event specification from the word designator.  It may be
       omitted if the word designator begins with a ^, $, *, -, or %.  Words
       are numbered from the beginning of the line, with the first word being
       denoted by 0 (zero).  Words are inserted into the current line
       separated by single spaces.
    
       *      All of the words but the zeroth.  This is a synonym for `1-$'.
              It is not an error to use * if there is just one word in the
              event; the empty string is returned in that case.
    
    • 11
  2. cas
    2022-01-03T18:15:28+08:002022-01-03T18:15:28+08:00

    除了按向上箭头和手动编辑输入行等显而易见的事情外,GNU Readline(由bash和其他几个程序使用)还内置了一些有用的历史编辑功能。 !*正如其他答案中提到的那样,其中之一。

    另一个是使用^. 来自man bash:

    ^string1^string2^

    快速替换。重复前面的命令,将 string1 替换为
    string2。等效于!!:s^string1^string2^(请参阅下面的修饰符)。

    使用它,您的命令可以通过键入^tyop^typo^并按 Enter 来修复。

    使用 bash 的历史可以做的事情还有很多。运行man bash并搜索HISTORY EXPANSION并阅读该部分和所有子部分(Event Designators、Word Designators和Modifiers)。

    顺便说一句,阅读标题部分也值得一读READLINE,或者至少略读一下以了解它的功能。关于 readline 的完整文档可以在https://tiswww.cwru.edu/php/chet/readline/rltop.html和https://tiswww.cwru.edu/php/chet/readline/readline.html找到

    • 9
  3. belkarx
    2022-01-03T16:58:30+08:002022-01-03T16:58:30+08:00

    该!$变量存储上一个命令的最后一个参数。

    例子:

    touch hello
    cat !$ #equivalent to "cat hello" 
    

    !*并$_存储所有参数。

    此处有更多详细信息和替代命令的类似问题

    • -2

相关问题

  • 使 mysql CLI 以交互方式向我询问密码

  • 有没有办法让 ls 只显示某些目录的隐藏文件?

  • grep -v grep 有什么作用

  • 没有服务器的命令行 pub/sub?

  • 如何将带有〜的路径保存到变量中?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve