executing aliases from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting executing aliases from a file
# 1  
Old 07-17-2012
[SOLVED] executing aliases from a file

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.

any help?

xxx

Last edited by didgewind; 07-22-2012 at 11:32 PM.. Reason: Solved
# 2  
Old 07-17-2012
You need to execute the script containing the alias in the current Shell.
e.g.
Code:
. ./scriptname

That is dot-space-dot-slash scriptname


Ps: Please remember to post what Operating System and version you are running and what Shell you use.
# 3  
Old 07-17-2012
some other already answered, and I don't know how to delete my post Smilie
# 4  
Old 07-17-2012
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:

Code:
. ~/.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?
# 5  
Old 07-22-2012
got it

interesting. Thanks for your answers, appreciated.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unsetting aliases

Within a session we have created some aliases. How to unset all the aliases in the session or specific alias? (1 Reply)
Discussion started by: pandeesh
1 Replies

2. Shell Programming and Scripting

Using Aliases in a script

Hi all, I have and alias set in .profile like alias ll='ls -la' I am writing a shell script in which i am using "ll" but it gives command not found . Can anyone please tell me how source aliases in the script we write do i need to define it again in every script i write is there any oher... (1 Reply)
Discussion started by: firestar
1 Replies

3. Shell Programming and Scripting

Creating and Executing a script of aliases in AIX

hi, I am trying to create a script in AIX (5.3 I think), then run it. here's what I have: /home/me $ vi first.aliases ... alias cdblah='cd /blah' alias cdho='cd /ho' alias ssr='sudo su - random' ~ ...end of first.aliases /home/me $ ./first.aliases /home/me $ ssr ksh: ssr: not found.... (2 Replies)
Discussion started by: heetertc
2 Replies

4. Shell Programming and Scripting

logic for executing defined seq in file and cmd in file

I have four files a,b,c,d which need to contain certain in the sequence a, b, c ,d , each file command which needs to be executed, what i m in need is that to executed file and cmd in the defined order and if any of the command FAIL or throw ERROR, it script shud come out... (3 Replies)
Discussion started by: tarunn.dubeyy
3 Replies

5. Shell Programming and Scripting

etc aliases

Hello: i have several server with own etc aliases. right now i want to combine it all into a general etc aliases in a new freebsd server. cause it consist hundred thousand of record user inside how to make a shell script to combine it or configure it. all etc aliases record example: ... (0 Replies)
Discussion started by: peterLfs
0 Replies

6. Solaris

oops...accidentally overwrote postfix aliases file

I have directory/dns server running sparc solaris 9. while troubleshooting another issue, i overwrote the aliases file on accident. my question is: is there any way to revert this? any help super appreciated...especially since this a production box! (2 Replies)
Discussion started by: JeepResQ
2 Replies

7. UNIX for Dummies Questions & Answers

man aliases

Can any one show me how to create an alias account that silently copies local emails to the administrator (root) using a linux cmd line or GUI? The answer needs to be very simplly explained at this stage, as I am new to the command prompt...expecialy in linux. thanks heaps guys Pipa:) I... (2 Replies)
Discussion started by: Pipa
2 Replies

8. Shell Programming and Scripting

Reading file names from a file and executing the relative file from shell script

Hi How can i dynamically read files names from a list file and execute them from a single shell script. Please help its urgent Thanks in Advance (4 Replies)
Discussion started by: anushilrai
4 Replies

9. UNIX for Dummies Questions & Answers

aliases

Is there a way to view what aliases are running on a given session? (1 Reply)
Discussion started by: BG_JrAdmin
1 Replies

10. Programming

aliases

Hi. I have a C program that is using the **environ pointer and I am trying to set up aliases for a system("/bin/ksh") call. This works for other environment variables but not for the aliases. Does anyone know if this can be done? Thanks ahead of time. (1 Reply)
Discussion started by: mluey61
1 Replies
Login or Register to Ask a Question