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 02-05-2014, 01:00 AM   #1
gonny95
Member
 
Registered: Feb 2014
Distribution: Slackware,Ubuntu
Posts: 84

Rep: Reputation: Disabled
Using global aliases in Slackware


First way:
In /etc/profile I just added alias hello="yes hello" doesn't work

Second way:
I made a file /etc/bashrc and put hello="yes hello"
And I edited /etc/profile like
Code:
#import /etc/bashrc to this file

if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi
But not working either

How to set aliases globally? ,not per-user
 
Old 02-05-2014, 01:11 AM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Use alias command before parameters, for example:
Code:
~$ alias hello='yes hello'
Then you check alias by invoking cmd:
Code:
user@system~$ alias
OR
user@system~$ alias <alias_name>
user@system~$ alias hello
Similarly, add the same cmd in ~/profile or ~/.bashrc. For global setting, do the same in /etc/bashrc or /etc/profile. Then source .profile or .bashrc and check it again.
Code:
user@system~$ source .bashrc
OR
user@system~$ source .prifle

Last edited by shivaa; 02-05-2014 at 01:13 AM. Reason: Formatting
 
Old 02-05-2014, 01:39 AM   #3
gonny95
Member
 
Registered: Feb 2014
Distribution: Slackware,Ubuntu
Posts: 84

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by shivaa View Post
Use alias command before parameters, for example:
Code:
~$ alias hello='yes hello'
Then you check alias by invoking cmd:
Code:
user@system~$ alias
OR
user@system~$ alias <alias_name>
user@system~$ alias hello
Similarly, add the same cmd in ~/profile or ~/.bashrc. For global setting, do the same in /etc/bashrc or /etc/profile. Then source .profile or .bashrc and check it again.
Code:
user@system~$ source .bashrc
OR
user@system~$ source .prifle
Oh, sorry those were typing errors

I already had written alias before parameters

not working..
 
Old 02-05-2014, 01:46 AM   #4
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Seems that those global files i.e. /etc/profile or /etc/bashrc ain't working in your case, because whenever your work, by default your own (per user) files are used (if they are available), not the global files. So you can do one thing: Define the same alias in your own files (~/.profile or ~/.bashrc) and check whether it work or not. Else, temporary move your ~/.profile or ~/.bashrc to some other place, logout from your session, and then login again and check those alias, bacause in that case system will read profile settings from global files.
 
Old 02-05-2014, 02:04 AM   #5
gonny95
Member
 
Registered: Feb 2014
Distribution: Slackware,Ubuntu
Posts: 84

Original Poster
Rep: Reputation: Disabled
Thanks but partially worked..

aliases are applied only in the case of ~/.bashrc

Only thing I have to do is make it global

It seems like slackware's problem
 
Old 02-05-2014, 03:11 AM   #6
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Originally Posted by gonny95 View Post
Thanks but partially worked..
What exactly did you do? Just add the same lines (i.e. alias hello='yes hello') in both /etc/bashrc and /etc/profile. Source these files and check it. Also, as far as I am concerned, each user will need to re-login to take changes into effect. Moreover, if it partially work, then append following entry in user's ~/.bashrc and ~/.profile file:
Code:
source /etc/profile
source /etc/bashrc
Note: After any change, source the file to take changes into effect.
 
Old 02-05-2014, 03:43 AM   #7
gonny95
Member
 
Registered: Feb 2014
Distribution: Slackware,Ubuntu
Posts: 84

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by shivaa View Post
What exactly did you do? Just add the same lines (i.e. alias hello='yes hello') in both /etc/bashrc and /etc/profile. Source these files and check it. Also, as far as I am concerned, each user will need to re-login to take changes into effect. Moreover, if it partially work, then append following entry in user's ~/.bashrc and ~/.profile file:
Code:
source /etc/profile
source /etc/bashrc
Note: After any change, source the file to take changes into effect.
When I typed source /etc/profile the alias was applied

But when I log off and log on , the alias was not applied

Well.. I guess Slackware doesn't use source command when logging on
 
Old 02-05-2014, 05:24 AM   #8
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
From /etc/profile in Slackware 14.1
Code:
# Append any additional sh scripts found in /etc/profile.d/:
for profile_script in /etc/profile.d/*.sh ; do
  if [ -x $profile_script ]; then
    . $profile_script
  fi
done
So, add your custom aliases to files (one for csh and one for bash) in /etc/profile.d/ and make them executable.
 
Old 02-05-2014, 06:25 AM   #9
gonny95
Member
 
Registered: Feb 2014
Distribution: Slackware,Ubuntu
Posts: 84

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by allend View Post
From /etc/profile in Slackware 14.1
Code:
# Append any additional sh scripts found in /etc/profile.d/:
for profile_script in /etc/profile.d/*.sh ; do
  if [ -x $profile_script ]; then
    . $profile_script
  fi
done
So, add your custom aliases to files (one for csh and one for bash) in /etc/profile.d/ and make them executable.

thanks I did as you said

/etc/profile.d/hello.sh
Code:
#!/bin/sh
alias hello="yes hello"

/etc/profile.d/hello.csh
Code:
#!/bin/csh
alias hello
When I reboot

The alias worked in tty very well

But in the terminal of xwindows

not working

Is this correct?
 
Old 02-05-2014, 08:42 AM   #10
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
Quote:
But in the terminal of xwindows

not working

Is this correct?
That seems odd. I see the aliases defined in the /etc/profile.d/coreutils-dircolors.(c)sh files in my terminals in X.
 
Old 02-05-2014, 09:47 AM   #11
brianL
LQ 5k Club
 
Registered: Jan 2006
Location: Oldham, Lancs, England
Distribution: Slackware64 15; SlackwareARM-current (aarch64); Debian 12
Posts: 8,298
Blog Entries: 61

Rep: Reputation: Disabled
Try creating a .bash_profile (as well as .bashrc) in your home directory, works for me:
Code:
if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi
According to this, aliases should work globally if they're in /etc/bashrc.

Last edited by brianL; 02-05-2014 at 09:55 AM.
 
Old 02-05-2014, 04:15 PM   #12
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
The problem is that when a terminal is started in X, it is started as an interactive shell that is not a login shell. This means that at startup, bash reads commands from ~/.bashrc. (Read the INVOCATION section of 'man bash').

In my ~/.bashrc I have:
Code:
. /etc/profile.d/coreutils-dircolors.sh
so the aliases are loaded.

If you were to do this generally for all users, you could look at creating a .bashrc file in /etc/skel so that when a user was added, a default ~/.bashrc was added. The default .bashrc could contain:
Code:
if [ -f /etc/bashrc ]; then
   source /etc/bashrc
fi
Then /etc/bashrc could be created to provide the aliases to all users.
 
Old 02-06-2014, 06:22 PM   #13
gonny95
Member
 
Registered: Feb 2014
Distribution: Slackware,Ubuntu
Posts: 84

Original Poster
Rep: Reputation: Disabled
Thanks for all your replies

Now I get it

I did like this:

In /etc/bashrc I added my aliases

And in ~/.bashrc add this code
Code:
if [ -f /etc/bashrc ]; then
   source /etc/bashrc
fi
Finally I copy ~/.bashrc to /etc/skel
 
  


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
wrap lines at 80 for long aliases in .aliases.csh jhwilliams Linux - Software 0 07-26-2007 07:49 AM
Permanent Command Aliases - Slackware 9.1 erraticassassin Slackware 3 01-09-2005 03:08 PM
where are global aliases stored? abs Slackware 5 08-27-2004 12:34 AM
Global Aliases--Nothing is working! mooreted Slackware 2 06-15-2004 09:52 PM
kinda global aliases? pal_o_matic Linux - Newbie 1 08-01-2003 02:32 AM

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

All times are GMT -5. The time now is 12:21 PM.

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