LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-17-2010, 03:43 PM   #1
markraem
Member
 
Registered: Nov 2003
Posts: 82

Rep: Reputation: 15
how a activate aliases from a script ?


I wrote a small script :
#cat myscript.sh

NEWFILE=dojas.sh
touch $NEWFILE
rm $NEWFILE
touch $NEWFILE
echo "alias jan1='telnet 10.10.10.1 '" >> $NEWFILE
echo "alias jan2='telnet 10.10.10.2 '" >> $NEWFILE

chmod 777 $NEWFILE
./$NEWFILE
exit 0
#
#
==> in that script I create some alias commands an pipe them to a new shell script (called dojas.sh)

however after execution of that script , I do not see the aliases jan1 and jan2 in my terminal.

Even if I execute the dojas.sh srcipt manually , I do not see the aliases in the alias output of my terminal.

The only way I can make the aliases active is do the following :
cat dojas.sh
copy and paste the alias rules, and they are active in my session.

How can I make sure that I can activate aliases and they are active in my terminal from a script ?
Note : I am not interested in .bashrc file, I want them to be active in my current session.
Thanks in advance
 
Old 01-17-2010, 03:49 PM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
./$NEWFILE


Instead of the above, try sourcing the new file like this exactly:

Code:
. ./$NEWFILE
So notice it's a period, a space, then the "./filename"

This should "source" the file into your current shells environment, giving you the aliases. But, I'm not really sure at all if this will be different than the way you were doing it. Try and see..

Sasha

PS - also: sourcing the aliases from WITHIN that script, will possibly not make the aliases work for the shell OUTSIDE the script. You might need to source the $NEWFILE after the script exits.
Let us know how it works.

Last edited by GrapefruiTgirl; 01-17-2010 at 03:52 PM.
 
Old 01-17-2010, 04:39 PM   #3
markraem
Member
 
Registered: Nov 2003
Posts: 82

Original Poster
Rep: Reputation: 15
sourcing . ./$NEWFILE in the script does not work.

./$NEWFILE outside the script does not work (as allready mentioned)

. ./$NEWFILE outside the script ( so doing this manauly after the script has run) that WORKS.

If there is nobody that comes with another solution, then I will use that one.
 
Old 01-17-2010, 08:00 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,355

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
The pint is that env vars (inc aliases) can only exist at the shell level they were defined, & optionally be exported down to child sub-shells (& sub-sub-shells etc).
They cannot be 'exported' upwards ... unless you use the

. ./file

but even then, that just creates them at the 'current' level, not any higher...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sendmail Aliases: forward mail to script mikeshn Linux - Software 2 07-03-2010 08:22 PM
I can't activate (i'mean activate) my wireless card Mardrus Linux - Newbie 5 05-04-2008 06:35 AM
wrap lines at 80 for long aliases in .aliases.csh jhwilliams Linux - Software 0 07-26-2007 07:49 AM
sendmail and NIS databases (aliases, mail.aliases) - what kind of databases? cotton213 Linux - Software 0 03-14-2006 05:57 PM
Cannot activate Javascript within Python script Linh Programming 0 09-22-2003 11:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 03:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration