Script to remove a file issue

I have a script to remove a backup file and it doesn’t work. All it contains is:

/file remove $backupfile

I have set all the permissions and still no joy. If I enter that command into the terminal it’s fine. Is this a limitation or am I doing something wrong?
Thanks

I would assume that either $backupfile variable is not defined or nothing is stored in it when executing script.

That variable is set in the Environment and my other script that uploads a file using FTP also uses this variable and it works.

When you are using in an other script then written to the global variable you have put into the other script at start :global backupfile; .

I’m sorry I don’t understand.
Script 1 - This script sets the variable using
:global backupfile ($backupname.“.backup”);
Script 2 - This script uses the variable to upload the file via FTP using the variable as the filename to upload. This works.
Script 3 - Tries to delete the file using the file name in the variable
/file remove $backupfile

So the variable is set as it works in Script 2. The content from Script 3 when run direct in terminal works. Maybe there is a restriction on letting scripts delete things?

When the global variable has been set in the first script, in a different script can I call it directly or do I have to read it and store it locally first?

In RouterOS you can have a certain amount of luck or randomness … :wink:

So did you try script3 with the line I suggested? It is not stored locally but you have to define it in a different script.

If it does not work then state the policies for that script.

Ok I understand what you are saying now. Works now thank you. I understood by reading the docs that the variable was already shared between scripts. And using the same script in terminal works. Anyway it’s all good now thanks.