我在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.
更多推荐
发布评论