用于清空回收站的脚本不工作(Script to empty recycle bin not working)

编程入门 行业动态 更新时间:2024-10-26 01:22:18
用于清空回收站的脚本不工作(Script to empty recycle bin not working)

我在minix上创建了一个回收站的脚本。 我将一个将删除的文件移动到文件夹而不是删除它。 我在rm命令上使用了alias命令来使用脚本而不是rm。 现在的问题是我必须清空回收站。 我写了这个脚本:

#!/bin/sh unalias rm rm -r "/home/recyclebin/*" alias rm='/home/scriptrm.sh' #

在这个脚本中我unalias rm命令,所以我可以再次使用它然后我清空回收站,然后再次使用将文件移动到回收站的脚本别名rm。 当我运行这个脚本时,它什么也没做。 我尝试只运行脚本来unalias rm,但是rm继续使用别名。 有谁知道发生了什么?

谢谢。

I have created a script of a recycle bin on minix. I move a file that will deleted to a folder instead of deleting it. I have used the alias command on rm command to use the script instead of rm. The problem now is that I have to empty the recycle bin. I wrote this script:

#!/bin/sh unalias rm rm -r "/home/recyclebin/*" alias rm='/home/scriptrm.sh' #

In this script I unalias rm command so I can use it again then I empty the recycle bin and then alias rm again with the script that moves files to recycle bin. When I run this script it does nothing. I tried only running the script to unalias rm but rm continues with the alias. Does anyone know what's happening?

Thank you.

最满意答案

有几件事需要解决。

你是(双)引用你的glob( * ),所以它实际上不会扩展为任何东西(除非你有一个实际命名为*的文件)。

您的脚本将在子进程中运行,因此设置/重置别名等将不会对调用脚本的父shell产生任何影响。 IOW,你最后不需要将它归结为原始形式。 并且它不会继承您现有的父shell的别名。 它们不是从父母那里导出的。

A couple things to fix.

You’re (double-)quoting your glob (*), so it won’t actually expand to anything (except if you have a file actually named * there).

Your script is going to run in a sub-process, so setting/resetting aliases and such will not have any effect in the parent shell that invokes your script. IOW, you don’t need to alias it back to an original form at the end. And it won’t inherit your existing parent shell’s aliases. They’re not exported from the parent.

更多推荐

本文发布于:2023-07-26 15:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1277561.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:回收站   清空   脚本   工作   Script

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!