LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 10-12-2010, 03:38 PM   #1
schachwizard
Member
 
Registered: Sep 2010
Location: Philly
Distribution: OpenSuse
Posts: 67

Rep: Reputation: 3
Bash Aliases Not Working


I've added a few bash aliases to my /.bashrc file. These are:

alias cp='cp -v -i'
alias rm='rm -i'
alias mv='mv -i'
alias mountfloppy='mount -t vfat /dev/fd0 /mnt/floppy/ | sudo nautilus'
alias umountfloppy='sudo umount /dev/fd0'

However, I cannot add certain others. For example, I would like:

alias df='df -h'
alias update='sudo apt-get update && sudo apt-get upgrade'

When I try 'df', I get the output of 'df', not 'df -h'.
When I type 'update', it says:
No command 'update' found, did you mean:
Command 'uupdate' from package 'devscripts' (main)
Command 'lupdate' from package 'libqt4-dev' (main)
Command 'lupdate' from package 'qt3-dev-tools' (main)
update: command not found

This isn't absolutely necessary, but I would especially like to be able to upgrade my software with one command. What am I doing wrong?
 
Old 10-12-2010, 03:46 PM   #2
jcmlq
Member
 
Registered: Aug 2009
Posts: 32

Rep: Reputation: 19
Silly question time, but did you '. ~/.bashrc' to make sure the new aliases had actually been read by your shell?
 
1 members found this post helpful.
Old 10-12-2010, 03:50 PM   #3
schachwizard
Member
 
Registered: Sep 2010
Location: Philly
Distribution: OpenSuse
Posts: 67

Original Poster
Rep: Reputation: 3
That worked. Thank you very much. I did not know I had to do that.

Oddly enough, I don't remember doing that before to make the other aliases work. Perhaps I restarted between adding them and testing them?

Also, since I'm relatively new to Linux, could you explain why that command worked? Why the period at the beginning? What does "~/.bashrc" do?
 
1 members found this post helpful.
Old 10-12-2010, 03:56 PM   #4
jcmlq
Member
 
Registered: Aug 2009
Posts: 32

Rep: Reputation: 19
The '.' or 'source' command read the file and execute it in the *current* shell. Normally when you run a script it gets run in a child shell and any changes (like creating aliases or functions or setting variables) don't happen in your working shell.

Oh yeah, the ~ means your home directory. So ~/.bashrc is a fully qualified path to a file in your home directory.

Last edited by jcmlq; 10-12-2010 at 04:01 PM.
 
Old 10-12-2010, 04:03 PM   #5
schachwizard
Member
 
Registered: Sep 2010
Location: Philly
Distribution: OpenSuse
Posts: 67

Original Poster
Rep: Reputation: 3
Thank you for taking the time to explain that.
 
Old 10-12-2010, 04:08 PM   #6
jcmlq
Member
 
Registered: Aug 2009
Posts: 32

Rep: Reputation: 19
np at all.
 
Old 10-12-2010, 04:21 PM   #7
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
I modify my settings often enough that I've set up an alias simply for reloading my bashrc.
Code:
alias reload_bash='. /etc/bash.bashrc ; . $HOME/.bashrc'
I personally prefer to use $HOME instead of ~ inside of scripts. It's slightly more readable in my view.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash macro expansion in aliases jhwilliams Linux - Software 2 06-10-2009 04:13 PM
aliases with bash shell edccmu22 Linux - Newbie 3 11-04-2007 11:59 AM
Bash aliases in OS X?? Grife Other *NIX 3 03-14-2007 06:26 AM
Bash aliases won't autostart? Ollir Mandriva 7 08-22-2004 02:10 PM
Make Screen respect bash aliases VxJasonxV Linux - Software 8 02-05-2004 03:00 AM


All times are GMT -5. The time now is 04:51 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration