windows - Linux Bash 和 Windows Batch 的自删除脚本

标签 windows bash batch-file self-destruction

我有一个卸载脚本,用于清理与应用程序一起使用的附加工具。 在 Windows 和 Linux 上运行的脚本版本。

我希望能够删除卸载脚本文件以及脚本运行的目录(对于 Windows 批处理文件和 Linux bash 文件)。现在,除了脚本和它运行的目录之外的所有内容在运行后都会保留。

如何删除脚本和脚本目录?

谢谢

最佳答案

在 Bash 中,你可以这样做

#!/bin/bash
# do your uninstallation here
# ...
# and now remove the script
rm $0
# and the entire directory
rmdir `dirname $0`

关于windows - Linux Bash 和 Windows Batch 的自删除脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7198281/

相关文章:

windows - 创建自定义协议(protocol) (Windows 7)

bash - 如何获取 CSV 中一列中不同值的总数?

postgresql - 使用 SIS 执行 postgres dbinit 的批处理文件给出了被拒绝的权限

batch-file - 在一行中计算一个确切的字符 - cmd

c++ - 如果应用程序崩溃(例如段错误或未处理的异常),由于某些 Win10 更新它现在似乎静静地死去

python - Windows 上的 ctypes : depending dlls not found

linux - 如何从不同的文本文件复制字符串以在单独的列中并排显示到 Bash 中的第三个文件中

windows - 计算文件中未知字符串最常见的出现次数

c++ - 在 MFC CScrollView 的固定位置显示子窗口

linux - 当用户想要删除 shell 中的特定文件时给出警告提示