在引号波浪线扩展 [英] Tilde expansion in quotes

查看:167
本文介绍了在引号波浪线扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个脚本,必须以其中可能含有波浪用户定义的目录中找到一些文件。该构造看起来像

I write a script where must find some files in a user-defined directory which may contain tilde. The construct looks like

found_files=$(find "$user_defined_directory" -type f … )

我用引号,以支付可能的空间在这条道路,但根据手册页引号波浪线扩展不起作用。我知道运营商大概可以做到这一点扩展,但我不能弄清楚如何在这里使用它

I use quotes to cover possible spaces in that path, but tilde expansion does not work in quotes according to man page. I know about : operator that probably can do this expansion, but I can’t figure out how to use it here.

用户自定义目录正在采取从用户$ HOME目录中其他配置文件。它不是传递给我的脚本作为参数,它被从在我写剧本的另一个配置解析。

The ‘user-defined-directory’ is being taken from another configuration file in user $HOME directory. It is not passing to my script as a parameter, it’s being parsed from that another config in the script I write.

推荐答案

您可以使用$ {user_defined_directory /#〜/ $ HOME}来取代〜 在当前用户的主目录的字符串的开头。请注意,这将不处理〜用户名/子目录格式,只是一个普通的。如果您需要处理更复杂的版本,你需要写一个更复杂的转换器。

You can use "${user_defined_directory/#~/$HOME}" to replace a "~" at the beginning of the string with the current user's home directory. Note that this won't handle the ~username/subdir format, only a plain ~. If you need to handle the more complex versions, you'll need to write a much more complex converter.

这篇关于在引号波浪线扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆