0

I have a number of self-made (bash) scripts that I often use. Here are some examples of these scripts:

  • A script backup-system.sh that backs up my system to an external hard drive.
  • A script repeat.sh that allows me to repeat a command multiple times. For example, repeat.sh 5 echo "x" prints "x" 5 times.
  • A script switch-sound.sh that switches between outputting sound over my loudspeaker and over my headset.

Because I use these scripts often, I want the ability to easily call them from my command line. For example, I want to type backup-system to run backup-system.sh.

How can I install my self-made scripts to run them from the command-line? Since this is a common issue, I would like to know the standard way to achieve this, that ideally works for many Linux distributions (however, Ubuntu is the priority).


More details:

  • I am the only user of my computer. Still, I would like to be able to use my scripts as both my own user and as root.
  • I know I could add an entry to .bashrc to achieve some of what I want. But because my scripts are often long, this is impractical.
Peter
  • 243
  • What do you mean by "because my scripts are often long" (that they consist of many command lines, or that their names are long and cumbersome to type)? – sudodus Dec 24 '17 at 17:19
  • 1
    Maybe you want to have a look into alias. – dessert Dec 24 '17 at 22:19
  • Rename your scripts to remove their .sh extension, put them in one of the directories specified under $PATH, and don't forget the #!/bin/bash in the first line on your scripts. – Mukesh Sai Kumar Dec 25 '17 at 15:15

0 Answers0