How to start a shell without any user configuration?
You can pass the --noprofile
and --norc
command-line options:
$ bash --noprofile --norc
You will find documentation about these options in the man page.
How do I run a shell script without using sh or bash commands?
Add a "shebang" at the top of your file:
#!/bin/bash
And make your file executable (chmod +x script.sh
).
Finally, modify your path to add the directory where your script is located:
export PATH=$PATH:/appropriate/directory
(typically, you want $HOME/bin
for storing your own scripts)
Execute a bash script the first time shell opens
Bash has two files, from the user perspective, that perform "setup" when it is launched:
.bash_profile
- This file is executed whenever you open an interactive login shell. This file may also be named.profile
in certain distributions or configurations..profile
is usually used for non-Bash specific configuration items. Also be aware that if you have the little used.bash_login
,.bash_profile
will prevent that file from being used, though it is otherwise equivalent..bash_profile
is standard..bashrc
- This file is executed for all other bash instances. Note that it is common for people to call.bashrc
from.bash_profile
to create consistency.
A login shell is spawned when you login; via ssh, telnet, at a console, etc. You can also force the launch of a login shell (forcing .bash_profile) to be processed by starting a shell under su
like so:
su - username
Here, the dash indicates that this should be processed as a login shell.
Neither of these seem to be the correct answer for your question, however, unless you are certain to login once each day and only once each day.
A better approach in your case would be to use the cron
. Crontab allows you to schedule jobs to run at any desired interval. For daily execution, you would likely want a line configured like so:
0 5 * * * /home/user/script
This would cause the user's script to execute at 5am every day. The columns are:
0 5 * * *
^ ^ ^ ^ ^------ Day of week
^ ^ ^ ^-------- Month of year
^ ^ ^---------- Day of month
^ ^------------ Hour of day
^-------------- Minute of hour
Each of those fields can also represent a comma separated list or even an arithmetic expression. For example, the following will execute the script four times during the 5 AM hour:
*/4 5 * * *
Terminal: Where is the shell start-up file?
You're probably using bash
so just add these 3 lines to ~/.bash_profile
:
$ cat >> ~/.bash_profile
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/directory-you-do-development-in
source /usr/local/bin/virtualenvwrapper.sh
^D
where ^D
means you type Control+D (EOF).
Then either close your terminal window and open a new one, or you can "reload" your .bash_profile
like this:
$ source ~/.bash_profile
Changing default shell in Linux
Try linux command chsh
.
The detailed command is chsh -s /bin/bash
.
It will prompt you to enter your password.
Your default login shell is /bin/bash
now. You must log out and log back in to see this change.
The following is quoted from man page:
The chsh command changes the user login shell. This determines the
name
of the users initial login command. A normal user may only change the
login shell for her own account, the superuser may change the login
shell for any account
This command will change the default login shell permanently.
Note: If your user account is remote such as on Kerberos authentication (e.g. Enterprise RHEL) then you will not be able to use chsh
.
Shell Script (not bash) : How to redirect script into su root?
If you are just asking how to do a herestring when the shell you are using does not support herestrings, then:
su root -c '/some/foo/command' << EOF
somepass
EOF
I can't write this response without at least remarking that passing a password this way is not secure.
Related Topics
How to Untar a Tar.Bz File in Unix
The Irq in Kernel Function Asm_Do_Irq() Is Different from the One I Request in Module
Crontab Day of the Week Syntax
Control Mouse by Writing to /Dev/Input/Mice
Encrypt a String Using Openssl Command Line
Refresh Net.Core.Somaxcomm (Or Any Sysctl Property) for Docker Containers
One Command to Create and Change Directory
Why Is Dd with the 'Direct' (O_Direct) Flag So Dramatically Faster
Getting Disconnection Notification Using Tcp Keep-Alive on Write Blocked Socket
Replacing Environment Variables in a Properties File
Can't Use a Variable Out of While and Pipe in Bash
Cmd 2>&1 > Log VS Cmd > Log 2>&1
Why Is Kernel Mapped to the Same Address Space as Processes
How to Use Variables in a Bash for Loop
Why Does Zookeeper Not Use My Log4J.Properties File Log Directory