简体   繁体   English

bash中的Escaping个字符

[英]Escaping characters in bash

  • I use thunar as a file manager我使用 thunar 作为文件管理器
  • I want to use "custom actions" on certain files (Thunar --> Edit --> Configure Custom Actions...)我想对某些文件使用“自定义操作”(Thunar --> 编辑 --> 配置自定义操作...)
  • the command I use is: xfce4-terminal -e "md5sum '%F'" --hold我使用的命令是: xfce4-terminal -e "md5sum '%F'" --hold

This works fine, except when the file path or file name contains a space.这工作正常,除非文件路径或文件名包含空格。 It just won't work as intended because the file can then not be found.它只是不会按预期工作,因为无法找到该文件。

I think this is because the spaces in the file path are not automatically escaped我认为这是因为文件路径中的空格没有自动转义

How do I solve this problem?我该如何解决这个问题? Thank you in advance先感谢您

Seems like Thunar replaces %F with (potentially multiple ) correctly quoted paths.似乎 Thunar 将%F替换为(可能是多个)正确引用的路径。 Putting this inside quotes will ruin the already perfect quoting.把这个放在引号内会破坏已经完美的引号。 From https://docs.xfce.org/xfce/thunar/custom-actions来自https://docs.xfce.org/xfce/thunar/custom-actions

Never quote field codes从不引用字段代码

You need a way to pass an argument list to a command running inside xfce4-terminal .您需要一种方法将参数列表传递给在xfce4-terminal中运行的命令。 Luckily man xfce4-terminal lists:幸运的是man xfce4-terminal列出了:

-x, --execute Execute the remainder of the command line inside the terminal -x, --execute在终端内执行命令行的其余部分

Therefore, try因此,尝试

xfce4-terminal --hold -x md5sum %F

You can easily escape a character with by placing a \ in front of it.您可以通过在字符前面放置一个\来轻松地转义字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM