Sponsored Content
Top Forums Shell Programming and Scripting How to do user-preset login to Bash shell then automate path modification? Post 303012312 by bakunin on Friday 2nd of February 2018 03:58:25 AM
Old 02-02-2018
When a bash shell starts several scripts are executed automatically. You can put whatever commands you want to have executed automatically there.

First, a (general) script is executed: /etc/profile. This is done for every user and therefore it should contain only settings/actions which should be equal for every user logging on.

Next a user-specific script is called: ~/.bash_profile (if the shell is called as bash) or ~/.profile (if the shell is called as sh). If you do not want to differentiate between these two you can create a symbolic link from one to the other.

These two files are executed for so-called "login-shells": if you connect to a system, identify yourself as a certain user, then a login-shell is started. Which one that is is determined in /etc/passwd, where the attributes of all users are stored. Here is an example line from a Linux system:

Code:
root:x:0:0:Superuser:/root:/bin/bash

It says that the user root needs to identify with a passwort (the x - the password itself is stored elsewhere), has the user ID 0, its primary group has the group ID 0, the users description is Superuser, its home directory is /root and its login shell is /bin/bash.

There are other (non-login) shells, which are i.e. started when you start an xterm (or konsole or another terminal emulator) in a graphical environment. These shell instances do NOT execute the files mentioned before but they read and execute a file called ~/.bashrc.

So, here is a simple what-is-where:

/etc/profile Put in there whatever every user should have set/executed.

~/.profile Put in there what the respective user should have executed upon login. To set the login shells environment to the same as every other shells environment (if this is desired) add as the last line of this script the lines:

Code:
ENV=~/.bashrc
. ~/.bashrc

This will execute ~/.bashrc for every login script. Notice the dot in front!

Code:
~/.bashrc     # WRONG
. ~/.bashrc   # CORRECT

This means the script is executed not in a subshell but in the same shell! Otherwise whatever you would set in there would be lost when the script ends!

~/.bashrc Put everything in there what you want to have executed in every shell. This file is also on a per-user basis. Notice that you already have a certain environment in a shell once it gets to executing this script. i.e. you want to do:

Code:
export PATH="$PATH:/some/added/path"

because if you do this:

Code:
export PATH="/some/added/path"

Whatever the PATH was before it would be reduced to the one directory mentioned.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

mistyped shell path, now i can't login as the only user that can su to root

i mistyped the location of bash and now i can't login as the only other user who belongs to wheel on my freebsd box. since i'm having many problems with samba, this has frozen my attempts to get things resolved with the former issue. i've been told that 'su -m' should do the trick, but it's... (3 Replies)
Discussion started by: xyyz
3 Replies

2. Solaris

How to get bash to be the login shell?

Is there a way to edit a .profile file that would let a user have bash as their login shell? We tried adding: exec /bin/bash --login to the .profile, but this produced an endless loop and we could not login using that account. Thanks! Aaron (8 Replies)
Discussion started by: amheck
8 Replies

3. Shell Programming and Scripting

Error in setting PATH variable in bash shell

Hi, I am new to shell scripting.I tried adding an entry to the path variable like below export PATH=$PATH:/opt/xxx/bin But am getting an error invalid identifier /opt/xxx/bin Can someone tell me the error above and correct me . Thanks and Regards, Padmini (2 Replies)
Discussion started by: padmisri
2 Replies

4. Shell Programming and Scripting

setting a path in bash shell

Hello all, Sorry if the question if stupid but I have no big experience with programming. I am trying to set a path to be used in a makefile.in, for installation of a Fortran code. The makefile.in contains the string $(CODE_NAME) Now, when I type in the bash shell export... (6 Replies)
Discussion started by: laura74
6 Replies

5. Shell Programming and Scripting

Automate CVS login using shell script

Hi, Can anyone pls help me to automate login to cvs. I basically want to login to cvs and update a file. the script always gets to the login and returns the prompt for a password. Is there any way to send the password in the script itself. Here is the script: #!/bin/ksh... (0 Replies)
Discussion started by: raghu_shekar
0 Replies

6. Shell Programming and Scripting

How to Login as another user through Shell script from current user[Not Root]

Hi Every body, I would need a shell script program to login as different user and perform some copy commands in the script. example: Supppose ora_toms is the active user ora_toms should be able to run a script where user: ftptomsp pass: XXX should login through and run the commands ... (9 Replies)
Discussion started by: ujjwal27
9 Replies

7. Shell Programming and Scripting

How to automate user selection options in shell script?

Hi There, I am trying to write a script which has to pick the prompted options by itself(i mean option to choose will be passed) here is real scenario i am trying to do. i have an executable(diagnos) which gets called in shell script, when the executable (diagnos) runs i get following as... (8 Replies)
Discussion started by: sairam_9191
8 Replies

8. Shell Programming and Scripting

How to ask for a path from the user in XML and shell?

I am working on a small plugin for Galaxy, which is written in shell script.The XML wrapper shows multiple options of paths where the user would like to store the file. I now want to add an option where the user can specify the path. Also,he can specify the name of the output file.As I am new to... (6 Replies)
Discussion started by: menorca
6 Replies

9. UNIX for Dummies Questions & Answers

Which of the following command displays your login shell in bash shell?

Options:: A)$shell B)echo $ bash C)echo $ O D)$ O (1 Reply)
Discussion started by: raghugowda
1 Replies

10. Shell Programming and Scripting

Automate OTPW login to ssh via bash script

Hello everyone. I'm a Linux novice trying out a lot of bash scripting lately, as it is so very addictive. Lately I have been setting up one of my boxes remotely and have been hardening it as much as possible. Please allow me to explain the scenario, as it does tend to become a little... (1 Reply)
Discussion started by: instro
1 Replies
All times are GMT -4. The time now is 10:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy