LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-06-2006, 12:54 PM   #1
lordofring
Member
 
Registered: Feb 2005
Posts: 91

Rep: Reputation: 15
alias within a script


Hello,

I have several aliases need to set. So I put them in a script. After running the script, there is no alias is defined. Could any one tell me why?

the script alias_in_script:
Code:
#!/bin/sh

alias myecho="echo me"
Then, I ran it.
Code:
/usr # ./alias_in_script
/usr # myecho
/bin/sh: myecho: not found
 
Old 03-06-2006, 01:25 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
When you 'run' a script, a new shell is launched, in which to run the script. The environment modifications, aliases, etc. do not pass up to the parent shell process. Moreover, the child shell process terminates, and all of it's changes are lost.

Most likely, what you really want to do is

Code:
source ./alias_in_script
This has the same effect as if you were typing everything that is in the script. It occurs in the shell that you are using, hence that changes you make are not lost.

--- rod.
 
Old 03-06-2006, 01:29 PM   #3
lordofring
Member
 
Registered: Feb 2005
Posts: 91

Original Poster
Rep: Reputation: 15
You are correct. Thanks, rod. source works fine on my fc3. But the other linux box with busybox 1.00pre9 does not have source. Is there any other solution?

lordofring

Last edited by lordofring; 03-06-2006 at 01:32 PM.
 
Old 03-06-2006, 01:57 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
'source' is a command built into most shells. If I recall correctly, busybox is either a distro with a minimalistic shell, or it is a minimal functionality shell. In some shells, the '.' command is an alias for 'source'. Otherwise, you will have to RTFM for your particular shell.

--- rod.
 
Old 03-06-2006, 02:49 PM   #5
lordofring
Member
 
Registered: Feb 2005
Posts: 91

Original Poster
Rep: Reputation: 15
Excellent answer. The "." command works for me. Thank you very much.

lordofring
 
  


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
Alias question (2 commands for one alias) gflores Linux - Newbie 3 01-21-2006 12:40 AM
alias does not work in shell script mannahazarika Programming 9 01-20-2006 01:56 PM
alias not workin inside a script sanjith11 Programming 7 08-31-2005 03:36 PM
Delay in shell script or alias jeopardyracing Linux - Newbie 6 09-21-2004 08:07 PM
How make a script in order to set global alias? RickHunter_Ve Linux - Newbie 7 06-08-2004 02:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:57 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