git bash shell .bashrc not working every time - linux

I have a .git directory in my Dropbox, to store data for my website. In the directory, I have a .bashrc file, like this:
directory and .bashrc
When I type this into the bash terminal, it echo's
$ source .bashrc
my login
but when I restart terminal, it echo's nothing. I have to source it again.
I've read a few posts about this issue, about having to source it again and again but they said that if you do it to .bashrc it will work everytime. Mine doesn't. Where am I messing up?

When bash goes looking for its startup files, it generally looks for .bashrc in your home directory (where it currently isn't).
If you want to source a separate .bashrc file, probably the easiest solution is to put something like this into your actual one (the one that bash will run), $HOME/.bashrc:
otherOne="/somewhere/else/.bashrc"
if [[ -x "${otherOne}" ]] ; then
. "${otherOne}"
fi

Related

Cat the contents of a .txt file to .bash_profile

I am setting up a .txt file on my dropbox which will auto-sync between my laptop and desktop. This .txt file contains all of contents of a .bash_profile that I want to keep in sync between these computers, including an alias that currently looks like this:
Profile configuration
alias bprofud="cat ~/Dropbox/profile.txt > ~/.bash_profle"
(where "bprofud" == a short name for bash profile update)
The idea here is that in order to keep any changes to my bash profile on either computer, I will simply have to edit the text file in my dropbox and then run "bprofud" on each machine.
This doesn't work though. And I am not sure why. It simply writes a new .bash_profile each time instead of overwriting the previous one.
I am running the latest version of MacOSX.
Any idea what might be going wrong?
The reason is a simple typo failure ;)
alias bprofud="cat ~/Dropbox/profile.txt > ~/.bash_profle"
should be
alias bprofud="cat ~/Dropbox/profile.txt > ~/.bash_profile"
you simply missed the "i"
You could simple have your profile source that dropbox file:
[[ -r ~/Dropbox/profile.txt ]] && . ~/Dropbox/profile.txt

How do you run bash script as a command?

I have a bash script, which I use for configuration of different parameters in text files in my wireless access media server.
The script is located in one directory, and because I do all of configurations using putty, I have to either use the full path of the file or move to the directory that contains the file. I would like to avoid this.
Is it possible to save the bash script in or edit the bash script so that I can run it as command, for example as cp or ls commands?
The script needs to be executable, with:
chmod +x scriptname
(or similar).
Also, you want the script to be located in a directory that is in your PATH.
To see your PATH use:
echo $PATH
Your choices are: to move (or link) the file into one of those directories, or to add the directory it is in to your PATH.
You can add a directory to your PATH with:
PATH=$PATH:/name/of/my/directory
and if you do this in the file $HOME/.bashrc it will happen for each of your shell's automatically.
You can place a softlink to the script under /usr/local/bin (Should be in $PATH like John said)
ln -s /path/to/script /usr/local/bin/scriptname
This should do the trick.
You can write a minimal wrapper in your home directory:
#!/bin/bash
exec /yourpath/yourfile.extension
And run your child script with this command ./NameOfYourScript
update: Unix hawks will probably say the first solution is a no-brainer because of the additional admin work it will load on you. Agreed, but on your requirements, my solution works :)
Otherwise, you can use an alias; you will have to amend your .bashrc
alias menu='bash /yourpath/menuScript.sh'
Another way is to run it with:
/bin/bash /path/to/script
Then the file doesn't need to be executable.

Changes to PATH variable not working

For the life of me, I can't seem to add my Quartus bin directory to the PATH variable.
To add for all users, I edited /etc/profile by adding the line below as follows: (opening the file with sudo gedit /etc/profile)
/home/jaco/altera/14.0/quartus/bin/
I close the file, execute . ./etc/profile, after which I execute echo $PATH. This displays the directory I've just added, but when I open another shell and execute echo $PATH again, the directory is gone.
What am I doing wrong?
I have never made changes to /etc/profile but I know that env variables, aliases etc can be added to ~/.bashrc. You usually have to start a new shell or run source ~/.bashrc after editing your .bashrc file to load the new cahnges.
I think you will have to add it to all users. Also (this helps for future accounts) you can add it in your /etc/skel/.bashrc file. That is the skeleton file used when creating new users.

Add a bash script to path

I want to add a small script to the linux PATH so I don't have to actually run it where it's physically placed on disk.
The script is quite simple is about giving apt-get access through a proxy I made it like this:
#!/bin/bash
array=( $# )
len=${#array[#]}
_args=${array[#]:1:$len}
sudo http_proxy="http://user:password#server:port" apt-get $_args
Then I saved this as apt-proxy.sh, set it to +x (chmod) and everything is working fine when I am in the directory where this file is placed.
My question is : how to add this apt-proxy to PATH so I can actually call it as if it where the real apt-get ? [from anywhere]
Looking for command line only solutions, if you know how to do by GUI its nice, but not what I am looking for.
Try this:
Save the script as apt-proxy (without the .sh extension) in some directory, like ~/bin.
Add ~/bin to your PATH, typing export PATH=$PATH:~/bin
If you need it permanently, add that last line in your ~/.bashrc. If you're using zsh, then add it to ~/.zshrc instead.
Then you can just run apt-proxy with your arguments and it will run anywhere.
Note that if you export the PATH variable in a specific window it won't update in other bash instances.
You want to define that directory to the path variable, not the actual binary e.g.
PATH=$MYDIR:$PATH
where MYDIR is defined as the directory containing your binary e.g.
PATH=/Users/username/bin:$PATH
You should put this in your startup script e.g. .bashrc such that it runs each time a shell process is invoked.
Note that order is important, and the PATH is evaluated such that if a script matching your name is found in an earlier entry in the path variable, then that's the one you'll execute. So you could name your script as apt-get and put it earlier in the path. I wouldn't do that since it's confusing. You may want to investigate shell aliases instead.
I note also that you say it works fine from your current directory. If by that you mean you have the current directory in your path (.) then that's a potential security risk. Someone could put some trojan variant of a common utility (e.g. ls) in a directory, then get you to cd to that directory and run it inadvertently.
As a final step, after following the solution form proposed by #jlhonora (https://stackoverflow.com/a/20054809/6311511), change the permissions of the files in the folder "~/bin". You can use this:
chmod -R 755 ~/bin
make an alias to the executable into the ~/.bash_profile file and then use it from anywhere or you can source the directory containing the executables you need run from anywhere and that will do the trick for you.
adding to #jlhonora
your changes in ~./bashrc or ~./zshrc won't reflect until you do
source ~./zshrc or source ./bashrc , or restart your pc

Where are alias' stored in Ubuntu 10.04

I'm using a command which I don't know where the information is stored.
alias nup='ps ax | grep "nginx"'
Where is this alias saved?
It depends upon your environment and configurations.
For bash, I would generally put it in a .bashrc file that in a home directory.
In ubuntu alias get stored in the .bashrc file.
If you are typing alias update_linux='sudo apt-get update' in the terminal, then it will create an alias temporarily. It works until you close your terminal.
To add an alias permanently you can edit ~/.bashrc and add the alias to it:
gedit ~/.bashrc
and add alias at the end
alias update_linux='sudo apt-get update'
Don't forget to refresh the .bashrc configuration, by running:
source ~/.bashrc
for more details on creating alias you can read following blog: Codebucket.
Try
grep alias ~/.*
grep alias /etc/*
to find most aliases. In /etc/default, /etc/environment, depending on your distribution (I read: ubuntu)/version there might be more in other /etc/ -subdirs.
I am using Ubuntu 14.04, and you may put your aliases directly in .bashrc, but you may also create a file in ~/.bash_aliases, which will hold your aliases separately and load them automatically.
By default, the .bash_aliases file is not there. You will need to create it, but first make sure you create it in the same directory as your .bashrc file
To find your .bashrc, you may use this:
sudo find / -name .bashrc -print
My output was:
/root/.bashrc
/home/ddropik/.bashrc
/etc/skel/.bashrc
As mentioned by OddityOverseer and ranendra, I am probably interested in the one in my home directory, that is /home/ddropik/.bashrc. So I navigate to my home directory, cd ~/
Now create the .bash_aliases file with touch .bash_aliases and then edit it with nano .bash_aliases. Add whatever aliases you want.
You won't be able to use your newly added aliases until you open a new terminal session, or reload your profile, --bash login
It's ussually in a file in your home directory, such as .aliases or something.
The question here is:
if I have an alias named 'shortcut,' how do I find out what file is defining that as an alias?
The best and most user-friendly way to do this is this:
sudo grep -roI alias\ nameOfAliasHere=\' /etc/ /home/yourUserName/
-r tells grep to read everything in the directory, and go through the directories recursively, Without it, grep will complain about what you want to do.
-o means print only the part of the line that matches your string
-I suppresses binary files in the results, because those will not help you find out where your alias is
The backslashes mean "treat the next character as part of the string, instead of the normal way you interpret it"
The command will go through everything, including subdirectories, in your home folder and in /etc
If you want to start with the most likely places, just do your home directory:
sudo grep -roI alias\ nameOfAliasHere=\' /home/yourUserName/
To search everywhere it's likely to be defined or mentioned, which can be handy, this:
sudo grep -oIr alias\ ls=\' / --exclude-dir={sys,proc,srv,media,tmp,sbin,bin,boot,mnt,recovery,run,backups,var}
A lot of things like to make the 'ls' command fancier, for example. Check out the comparison below. I also included 'time' at the beginning for kicks:
You can see that there are a couple places outside of your home dir and /etc that have that alias, and it's also defined in both .alias and .bashrc. Personally, I like to throw my custom aliases in a file called .alias, and then tell everything to source it. If you're having trouble with an alias you're trying to define, that's handy. The things you see in the ~/Downloads and .cache directories won't affect your active aliases. Same with the /usr directory.
The file in /etc/skel is used to create home directories for new users, so anything there doesn't affect you. If something shows up in /etc/profile though, that will.
You can also see that the root user has an alias for ls.

Resources