LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using global aliases in Slackware (https://www.linuxquestions.org/questions/linux-newbie-8/using-global-aliases-in-slackware-4175493765/)

gonny95 02-05-2014 01:00 AM

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

shivaa 02-05-2014 01:11 AM

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


gonny95 02-05-2014 01:39 AM

Quote:

Originally Posted by shivaa (Post 5111809)
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..

shivaa 02-05-2014 01:46 AM

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.

gonny95 02-05-2014 02:04 AM

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

shivaa 02-05-2014 03:11 AM

Quote:

Originally Posted by gonny95 (Post 5111854)
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.

gonny95 02-05-2014 03:43 AM

Quote:

Originally Posted by shivaa (Post 5111881)
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

allend 02-05-2014 05:24 AM

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.

gonny95 02-05-2014 06:25 AM

Quote:

Originally Posted by allend (Post 5111935)
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?

allend 02-05-2014 08:42 AM

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.

brianL 02-05-2014 09:47 AM

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.

allend 02-05-2014 04:15 PM

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.

gonny95 02-06-2014 06:22 PM

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


All times are GMT -5. The time now is 07:45 PM.