1

I am very new to bash, I don't even know if what I want is possible. Sorry in advance if unknowingly I am asking for too much and it isn't possible.

I execute many different bash scripts for testing and learning process too frequently after doing small edits.

It's really annoying to type the whole command over and over again every minute, it wastes lot of my time.

For example, currently to execute the script I always enter

su -c sh /sdcard/downloads/script1.sh

Is there anyway I can assign this whole command to be initiated by just entering a single word? I would like to just type e.g.

script1 

This should actually execute

su -c sh /sdcard/downloads/script1.sh 

(or any defined command for that instance).

In short, there would be many pairs of a single word and it's corresponding command so that it will save my time.

And this thing should be permanent.

Even if I close the terminal and reopen it and enter my assigned word, it should run the corresponding defined command.

I hope there's a way to do it.

Kusalananda
  • 333,661

2 Answers2

2

Create alias in your ~/.bashrc file:

alias script1='su -c sh /sdcard/downloads/script1.sh'

The alias will then be available in the next shell session that your start.

Kusalananda
  • 333,661
0

alias script1="su -c /sdcard/downloads/script1.sh && su -c /sdcard/downloads/script2.sh'. Does this seem correct ?

Not really. That is probably not the road to take. It is just not practical. It works for this alias and these two scripts at their present location, but you don't want to create aliases for every script you call. You mention "many different scripts for learning".

You have to organize your tab completion, command history, PATH, aliases, functions, scripts, bash login (.bashrc). It does not take much, but it has to be coordinated.

nb: the alias command itself is tab-completable. And readline function shell-expand-line can expand the alias before you execute. That means you can scri<tab><M-C-e> and you get the whole line, so you can edit before you hit enter. Just to show what is possible.

To repeat special commands you rather use command history. To execute normal scripts you use shell functionality like alias, PATH, functions and other scripts.

  • Thanks for confirmation – Badal Singh Oct 07 '19 at 06:11
  • you're welcome...btw I am afraid you have to somehow read the bash manual. Start with the parts you think are interesting. Or you go through some general shell tutorials. The su part confuses me a bit in your example: this does not make it easier! –  Oct 07 '19 at 06:43