gpt4 book ai didi

bash - 为什么 '' GLOBIGNORE=keepfile rm *''删除keepfile?

转载 作者:行者123 更新时间:2023-12-05 01:24:45 25 4
gpt4 key购买 nike

有些东西我没有真正得到:

touch a b c ; mkdir -p git ; mkdir -p iii/ooo/ppp ; touch git/rtdsfgsdg  ; touch .sdfsadf

那么,这是否产生了我想要的结果?

» tree -a
.
├── a
├── b
├── c
├── git
│   └── rtdsfgsdg
├── iii
│   └── ooo
│   └── ppp
└── .sdfsadf

4 directories, 5 files

是的。一些文件,一个目录,一个隐藏文件。一切顺利。

现在我想删除所有东西,但我想保留隐藏文件和git目录。 GLOBIGNORE 助您一臂之力!

GLOBIGNORE=git rm -rf *

进展如何?

» tree -a
.
└── .sdfsadf

0 directories, 1 file

简直糟透了。我的 git 文件夹在哪里?为什么 GLOBIGNORE 没有像宣传的那样工作?

   GLOBIGNORE
A colon-separated list of patterns defining the set of file
names to be ignored by pathname expansion. If a file name
matched by a pathname expansion pattern also matches one of the
patterns in GLOBIGNORE, it is removed from the list of matches.

我在:

» bash --version
GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

最佳答案

您用来临时应用变量的语法仅适用于执行时,不适用于解析时;因此,它无法更改 glob 的扩展方式,因为在调用 rm 之前用文件列表替换 *

要修改解析时行为,请分成两个单独的命令:

GLOBIGNORE=git
rm -rf *

https://replit.com/@CharlesDuffy2/LovablePoliticalPrograms 看到这个运行成功

关于bash - 为什么 '' GLOBIGNORE=keepfile rm *''删除keepfile?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71225706/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com