How to do user-preset login to Bash shell then automate path modification?
How do a user login with full user-environment preset to Bash shell then automatically do path modification with few script codes, either on command-line or put it in a script file.
what i tried:
with no avail
Anybody please usefully and sincerely help me...
Thanks in advance
Last edited by Scrutinizer; 02-02-2018 at 01:52 AM..
Reason: code tags
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:
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:
This will execute ~/.bashrc for every login script. Notice the dot in front!
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:
because if you do this:
Whatever the PATH was before it would be reduced to the one directory mentioned.
I'm not quite sure what you are trying to achieve. I think you are wanting to customise the environment by settings the PATH, variables, current directory etc. You would be better writing a script with the settings in and the you can source it.
Something like:- my_env_1my_env_2
etc.
You can then (from the shell prompt or within a sh/ksh/bash script) do source my_eny_1 or shorthand, you could . my_env_2 and it will set the various variables/values/directory etc. in the current shell. You could even (in .bashrc perhaps) create an alias to call this in for you, e.g. alias DEV1='source my_env_1 would allow you to just type DEV1 on the command line to set it up.
You need to be careful because switching back & forth between these two would grow the PATH variable each time, possibly leading to confusion.
Does that help, or have I missed the request entirely?
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)
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)
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)
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)
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)
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)
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)
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)
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)