小编Mic*_*aël的帖子

find(1):如何实现星通配符使其在某些文件名上失败?

在文件名为 UTF-8 的文件系统中,我有一个名称错误的文件;它显示为:D?sinstaller,实际名称根据 zsh: D$'\351'sinstaller,Latin1 for Désinstaller,本身是法语“卸载”的野蛮行为。Zsh 不会与它匹配,[[ $file =~ '^.*$' ]]但会与通配符匹配*——这是我期望的行为。

现在我仍然希望在运行时找到它find . -name '*'——事实上,我从不希望文件名在这个测试中失败。然而,随着LANG=en_US.utf8,该文件确实露面,我必须集LANG=C(或en_US,或'')为它工作。

问题: 背后的实现是什么,我怎么能预测到那个结果?

信息:Arch Linux 3.14.37-1-lts,查找(GNU findutils)4.4.2

shell character-encoding find filenames wildcards

32
推荐指数
2
解决办法
1682
查看次数

用它的协进程/子进程替换当前进程

我有一个程序P希望收到“你好”并输出“为什么?” 在提供功能之前。此功能被其他程序使用,这些程序不知道以“Hello”开始对话是一种常见的礼貌。因此,我想为P这样的工作编写一个包装器(zsh 语法):

coproc P
print -p Hello  # Send Hello to P
read -pr line   # Read what P has to say
[[ "$line" = "Why?" ]] && Replace current process with the coprocess.
echo Could not get P's attention.
Run Code Online (Sandbox Code Playgroud)

在部分(类似)中使用cat或 会导致不必要的缓冲。我有哪些选择?ddReplace...cat <&p &; exec cat >&p

shell scripting process zsh

10
推荐指数
1
解决办法
495
查看次数

在 ZSH 中,如何取消设置任意关联数组元素?

我拥有的关联数组具有任意键,包括包含反引号、方括号等的键:

$ typeset -A arr
$ key='`'
$ arr[$key]=backquote
$ echo $arr[$key]
backquote
Run Code Online (Sandbox Code Playgroud)

我现在需要取消设置arr[$key]。通过网络查看,我尝试了:

$ unset "arr[$key]"
unset: arr[`]: invalid parameter name
$ unset "arr[${(b)key}]"
unset: arr[`]: invalid parameter name
Run Code Online (Sandbox Code Playgroud)

……没有运气。现在,我有点幸运,因为这提供了一条错误消息;在以下情况下,除了结果之外似乎没有任何失败:

$ typeset -A arr
$ key='?~>#'
$ arr[$key]=symbols
$ echo "$arr[$key]"
symbols
$ unset "arr[${(b)key}]"
$ echo "$arr[$key]"
symbols
Run Code Online (Sandbox Code Playgroud)

事实上, 中的任何符号?~>#都会触发相同的行为。

关于正在发生的事情以及如何获得预期行为的任何澄清?

注意:这个问题与 ZSH 邮件列表上的几个主题相关,标题与这个问题相似(这里那里)。

zsh associative-array

5
推荐指数
1
解决办法
237
查看次数

在ZSH中,哪些算术表达式可以作为数组下标出现?

ZSH 手册 ( zshparam(1)) 写道:

Array Subscripts
       Individual elements of an array may be selected using a subscript.  A
       subscript of the form `[exp]' selects the single element exp, where
       exp is an arithmetic expression which will be subject to arithmetic
       expansion as if it were surrounded by `$((...))'.
Run Code Online (Sandbox Code Playgroud)

然而,这很快就失败了:

mc% arr=(a b c d e)     
mc% echo $arr[$#arr]    
e
mc% echo $arr[$(($#arr))]
e
mc% echo $arr[$(($#arr - 1))]
d
mc% echo $arr[$#arr - 1]  
zsh: invalid subscript
Run Code Online (Sandbox Code Playgroud)

问题: …

zsh array arithmetic

4
推荐指数
1
解决办法
64
查看次数