Instead of telling you how to do it, I will tell you that you should not be doing that.
TL;DR - Do not change your script. Instead configure your file manager or figure out why your users accidentally run it.
EDIT: You seem to treat your script as somehow special, as if the general settings are not good enough and your script needs special confirmation from the user. Double clicking on it is the confirmation. If you find that your users run it by accident then you have to figure out why they do it and solve that instead. Then your real problem is not how to require confirmation but how to prevent your users from running it accidentally.
From the way you expose your problem it seems that you expect your program (script) to be run by navigating to where the file is, and then clicking on it from the file manager. Think about all other programs in your system. How many do you start like that? Do you navigate to /usr/local/bin
when starting firefox? Of course you do not. You click on it from the applications menu. (gnome tweak is a python script maybe that's a better example)
Hopefully you will not consider clicking on it from the applications menu an accident. So your problem becomes how to make you script appear there instead of using the file manager. To do this, you do the following things:
place your script away from the other files where the user may click on it by accident (the typical place is /usr/local/bin/
for a system wide installation or ~/.local/bin/
for a user install)
create a Desktop Entry file (read the standard specifications). Here's a minimal case:
[Desktop Entry]
Name=Your script name
Exec=path/for/your/script
Icon=path/for/your/icon/can/be/svg
Terminal=false
Type=Application
and shove it in /usr/local/share/applications/your-script.xml
or ~/.local/share/your-script.xml
.
Finally run update-desktop-database
.
Since you are double clicking on the script, it's the job of your file manager to confirm this. It is not the job of the script to confirm whether it should run. Take this to the extreme. Can you imagine how ridiculous it would be that each time you called any program you had to confirm it?
The only time when a program should ask for confirmation is when it is about to do something possibly dangerous and irreversible. For example, overwriting a file or bypassing the trash. And note that even these examples are about making a program do something specific. They are not about starting such programs. If a program only purpose is to do such dangerous thing, then it shouldn't be asking confirmation either.
Indeed, Nautilus (Gnome file manager) will already by default ask you to confirm if you want to execute a script (or just open it in a text editor).
And of course, this behaviour is configurable, giving the user the possibility of turning it off (note entry on Executable Text Files).
So do not add an annoying confirmation dialog to your script. Configure your file manager correctly. And let your users do the same.