-1

Let's say I have a bash program named Egample.sh and I moved it in /usr/bin. What would happen? What would it do to my program?

I don't know what would really happen. Some says putting my program in /usr/bin will make my program run by just typing the name of my program. So instead of: $ bash egample.sh It will run by just typing: $ egample.sh

However some people say I shouldn't do it. That's why I'm curious.

No Name
  • 13
  • It will be in /usr/bin folder according to filesystem. – Ipor Sircer Oct 29 '20 at 14:43
  • Then what would it do to my program? – No Name Oct 29 '20 at 14:47
  • 2
    What do you think would happen? Something bad? Basically, the worse that could happen is any user could invoke your script without giving the full path to it, if their PATH environment variable includes /usr/bin in it; which is extremely likely. Do you have security or safety concerns? Does your script include a rm -rf * command? – Mark Stewart Oct 29 '20 at 14:50
  • 1
    Any relative paths it uses (for config or data files, or other scripts and executables it references) will fail. – Paul_Pedant Oct 29 '20 at 15:00
  • I don't know what would really happen. Some says putting my program in /usr/bin will make my program run by just typing the name of my program. So instead of $ bash egample.sh it will run by just typing $ egample.sh However some people say I shouldn't do it. That's why I'm curious. – No Name Oct 29 '20 at 15:07
  • 1
    if that is the only purpose and you're the only user of that script, create ~/bin directory and add that to Path, e.g. https://unix.stackexchange.com/questions/131310/add-home-bin-to-path-for-a-single-user-in-debian-wheezy-with-lxde. Then move your file there. – pLumo Oct 29 '20 at 15:20
  • Possibly interesting/related: https://unix.stackexchange.com/q/389969/315749 (note that /bin VS /usr/bin is a different issue; they can be seen as equivalent in this case). – fra-san Oct 29 '20 at 18:20

1 Answers1

0

This situation depends on which scripts are in the shell scripting file. For example; Yes, it is dangerous if there is a "delete all files in the directory" command in the Egample.sh file and you have granted chmod + x privilege.

rm *

The above command will delete all files in the directory where it is located.

If your goal is to run a sh snippet with just the filename, without entering sh Egample.sh then you can use the PATH feature.

export PATH=$PATH:/file/path
source ~/.bashrc

I recommend you to learn more about File System Hierarchy. Up-to-date information on the FHS standard is available at https://www.pathname.com/fhs/.

You can also create a cron and run Egample.sh periodically. Everything is files in Linux and there are many alternatives to doing something. In order to find a suitable alternative, the purpose must be fully explained.

AdminBee
  • 22,803
menderes
  • 76
  • 3