It is necessary that the script itself is crammed into alias for the current user. edit .bashrc then we can from the script, but there is no update to the alias list. The ideal script behavior: - the first run of the sh script (alias sc is added) - repeated launches as sc


I add using the shell script alias:

echo "alias sc='sh ~/script.sh'" >> ~/.bashrc 

After that you should run the bashrc script itself so that the changes take effect before the reboot. If you run:

 . ~/.bashrc 

Nothing will happen, tk. The file will simply be included in the script. Actually the question is how to update the list of aliases from the script?

 alias alias_command_name='commands' 

It does not help, because it will work only for the current session.

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky
  • running a script creates a new process. This process will not affect your “main” shell process. - aleksandr barakin
  • Then what is the question? For each user, a separate .bashrc is created with its own aliases. - Yaroslav

1 answer 1

As an option. create a variable and watch what the variable is equal to. and add alias

 if [ {run:-0} -eq 0 ] then export run=1 alias sc='sh ~/script.sh' else 

And I do not advise you to add a line to .bashrc otherwise, with multiple launches, you will have a lot of added lines

  • To avoid duplicates check: if! grep "alias sc" ~ / .bashrc> / dev / null. If I understand you correctly, you are proposing to place this piece of code in bashrc, but how will we pass the variable there? - Anton
  • This block is placed in .bashrc and when it is first started it creates a changing run, when restarted, the variable is already there and this block will be ignored. Well, yes, if bash will be launched from one session. that will work. But if in different sessions, it is not - Yaroslav