hi there, i've got this alias i want assign only sometimes, and then work in the same shell with it (so when closing the shell the alias dissapears). As the alias is long, i want it to be in a executable file, so i just execute the script from a terminal and then i can access the alias from that same terminal. I've been playing with alias and export, but after executing the script, the alias is not recognized in the terminal.
You'll need to source the file, rather than executing it. If you execute it, the script is run in a child process and the shell that invoked it will not "see" any variables, aliases etc. that are created/changed in the child. By sourcing the file, you cause it to be interpreted by the current shell as though you had entered the commands at the command line.
I would add it to my profile, but assuming you don't want the alias in your .profile, you could create a file in your home directory called .special . When you want to set the alias, execute the following command:
. ~/.special
That dot (.) is the source command and will cause the interpreter to parse the named file and process it just as if it had been typed at the command line.
---------- Post updated at 22:37 ---------- Previous update was at 22:36 ----------
Guess we all said the same thing at roughly the same time. Great minds, no?