当前位置: 首页 > news >正文

bash alias 多引号问题

一句话:

像python那样,在''里面使用'\'abc\'',在bash中不行

 

需要把

\'

换成

'\''

这样问题解决

 

You can make that command into a Bash alias by editing your shell configuration file (typically ~/.bashrc or ~/.bash_aliases).

Here’s the step-by-step procedure:


1. Open your .bashrc (or .bash_aliases) file

nano ~/.bashrc

2. Add the alias definition

At the end of the file, add a line like this:

alias qbstat='ps aux | grep qbittorrent | awk '\''{printf "%-7s %-7s %-20s\n", $1, $2, $12}'\'''

Explanation:

  • You need to escape single quotes properly because of the nested quoting.

  • The '\'' sequence is how you embed a literal ' inside a single-quoted string in Bash.


3. Reload your shell configuration

source ~/.bashrc

4. Use your alias

qbstat

It should print output formatted as:

USER    PID     COMMAND
user1   1234    qbittorrent-nox

⚙️ Optional improvement

If you want to automatically exclude the grep qbittorrent process from showing up, modify the alias like this:

alias qbstat='ps aux | grep qbittorrent | grep -v grep | awk '\''{printf "%-7s %-7s %-20s\n", $1, $2, $12}'\'''

Would you like me to show you a more robust variant that doesn’t rely on grep (e.g., using pgrep or ps -C qbittorrent)? That’s cleaner and safer for scripting.

 

http://www.hskmm.com/?act=detail&tid=29045

相关文章:

  • 关于近期调研各类游戏开发引擎的一些感想
  • Electron38-Vue3OS客户端OS系统|vite7+electron38+arco桌面os后台管理
  • 终于在vim中用上了molokai的炫酷色彩配置了(゚∀゚)
  • 我是如何在Vim8.1中安装好的NERDTree插件的
  • Kafka监控工具 EFAK-AI 介绍
  • 视频拍摄技巧 - 希区柯克变焦/滑动变焦 All In One
  • 信息化说课-教学设计(6)
  • 记录:git
  • 实验1 现代C++编程初体验
  • 10.11总结
  • 2025年10月门窗十大品牌最新推荐榜单,十大品牌测评排名与选择指南
  • CF60E Mushroom Gnomes
  • CF691E Xor-sequences
  • LCPC12E - Johnnys Empire 题解
  • 中微笔记-cp.1 技术
  • P1896 [SCOI2005] 互不侵犯小总结
  • 美国能源部《生成式人工智能参考指南》解读
  • 分析InfluxDB中读取时CPU飙升
  • win10系统访问smb服务时提示密码错误
  • 《小说课》读书笔记
  • 2025-10-11?
  • 高二停课周记(信息学竞赛) Week1
  • AtCoder Beginner Contest 427 ABCDEF 题目解析
  • zju博士资格考试考前复习(微分方程方向)ode 部分
  • 测试一下博客功能
  • AI如何改变芯片设计
  • NOIP 2024
  • 2025/10/11
  • 好玩热门的switch游戏推荐【PC+安卓】塞尔达传说:王国之泪|v1.4.2整合版|官方中文| 附switch模拟器
  • 十年运维工程师总结