LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-08-2006, 02:14 AM   #1
oferu
LQ Newbie
 
Registered: Apr 2006
Posts: 8

Rep: Reputation: 0
Calling a script from within rc.local does not work.


Hi,
I have a simple script names 'aliases' under /home/oferu/:

#!/bin/sh
alias cdforms='cd /usr/local/forms'
alias cdhome='cd /home/oferu'

In rc.local, on the last line I have
source /home/oferu/aliases

But after I boot, the aliases do not exist.
Why?

Thanks.
 
Old 06-08-2006, 02:41 AM   #2
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
I'm guessing that rc.local, like any scripts in /etc/rc.d (or /etc/init.d for that matter) only get executed when the runlevel changes. So, yes, the script probably does run and sources your aliases stuff.
However, the aliases settings are not retained to your login shell probably.
So, when you start a shell, you will not inherit them either.

To fix this, put the "source ..." command not in /etc/rc.local but rather in /home/you/.profile, /home/you/.<your_shell>rc (ie /home/you/.bashrc) if they are only to be applied to your user. If you want to apply the aliases for all users, put them in /etc/profile or /etc/<some_shell>rc (ie /etc/bashrc).
 
Old 06-08-2006, 02:42 AM   #3
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
If you want the user oferu to be able to use those aliases, you should probably place the commands in /home/oferu/.profile, /home/oferu/.bash_profile or /home/oferu/.alias, depending on your configuration. There's also a file for system-wide settings like these (probably /etc/profile).

Edit: Well, at least the answer I gave looks similar to that of timmeke

Last edited by spirit receiver; 06-08-2006 at 02:45 AM.
 
Old 06-08-2006, 02:43 AM   #4
dimsh
Member
 
Registered: Aug 2005
Distribution: Debian, Ubuntu, Fedora
Posts: 74

Rep: Reputation: 15
hi,

I would do it like this:

1st: remove the first line from "/home/oferu/aliases" which is "#!/bin/sh"
2nd: instead of "source /home/oferu/aliases" use ". /home/oferu/aliases" (dot space filename), this is the include statement for bash.

it should work this way.

edit: NOTE: source command will execute the command line given to it and exit (like exec command), any commands below the source command in your rc.local will not be executed.

Regards.

Last edited by dimsh; 06-08-2006 at 02:53 AM.
 
Old 06-08-2006, 03:30 AM   #5
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Rep: Reputation: 31
Quote:
1st: remove the first line from "/home/oferu/aliases" which is "#!/bin/sh"
Any line beginning with a # will be ignored, even if the file is being sourced. The presence of this line shouldn't be a problem.

Quote:
source command will execute the command line given to it and exit (like exec command), any commands below the source command in your rc.local will not be executed.
This is not so. An excerpt from the bash texinfo manual:

Code:
`.    (a period)'
          . FILENAME [ARGUMENTS]
     Read and execute commands from the FILENAME argument in the
     current shell context.  If FILENAME does not contain a slash, the
     `PATH' variable is used to find FILENAME.  When Bash is not in
     POSIX mode, the current directory is searched if FILENAME is not
     found in `$PATH'.  If any ARGUMENTS are supplied, they become the
     positional parameters when FILENAME is executed.  Otherwise the
     positional parameters are unchanged.  The return status is the
     exit status of the last command executed, or zero if no commands
     are executed.  If FILENAME is not found, or cannot be read, the
     return status is non-zero.  This builtin is equivalent to `source'.
The source (or .) command will not prevent the rest of your script from executing.

As timmeke and spirit receiver have noted, aliases set from within a startup shell script (or any shell script, for that matter) will not be inherited by the login shell.

Simply moving the source (or .) line into /etc/profile or ~/.profile will solve your problem.

Last edited by zhangmaike; 06-08-2006 at 03:36 AM.
 
Old 06-08-2006, 04:57 AM   #6
oferu
LQ Newbie
 
Registered: Apr 2006
Posts: 8

Original Poster
Rep: Reputation: 0
Thank You all for your quick replies.
 
Old 06-08-2006, 07:24 AM   #7
worzel68
Member
 
Registered: May 2006
Location: Sydney
Distribution: FC5, FC3, AIX, System V,
Posts: 50

Rep: Reputation: 15
home directory

To change quickly to your home directory from anywhere you can do this:

cd ~

A small thing I know, but it could be worthwhile!
 
Old 06-08-2006, 10:24 AM   #8
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
@worzel68:
Code:
cd
is even simpler.
 
Old 06-09-2006, 12:56 AM   #9
worzel68
Member
 
Registered: May 2006
Location: Sydney
Distribution: FC5, FC3, AIX, System V,
Posts: 50

Rep: Reputation: 15
Excellent!! ha ha ha ha

Maybe we should explain to oferu that one can use the ~ to expand to one's home directory like this:

instead of;

cd /home/dave/kdevelop

or

cd
cd kdevelop

I could do this

cd ~/kdevelop

also one can join commands together with a semi-colon like this:

cd; ls -l

or just do this

ls -l ~

there are many ways of doing stuff

Last edited by worzel68; 06-09-2006 at 06:25 AM.
 
Old 06-12-2006, 02:37 AM   #10
oferu
LQ Newbie
 
Registered: Apr 2006
Posts: 8

Original Poster
Rep: Reputation: 0
New and simple

Nice to learn new and simple little commands that make navigation easier.
Thanks all.
 
  


Reply



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
How to check calling program/script? (C/C++) R00ts Programming 4 03-29-2006 02:51 PM
bash script calling mplayer afrodocter Programming 13 08-23-2005 10:41 AM
Directory listing - Calling shell script from a CGI script seran Programming 6 08-11-2005 11:08 PM
calling another script to be run. sonesay Programming 2 05-23-2004 06:08 AM
Calling All Script Guru's Shinobi Linux - General 5 04-02-2003 03:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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