0

I have the following code in my .bashrc:

c() { cd "$@" && ls -a ; }
alias cdd="c ~/Downloads"
alias r=". ~/.bashrc"

When I load a new terminal, cdd doesn't work before I do the r command. But after doing so, it works as intended. Why is this?

I asked this same question on Stack Overflow a few months ago, but none of the responses were able to give me a working solution. Here is the link to my dotfiles if that will be of any use.

EDIT type -a c cdd r produces:

c is aliased to `clear'
c is a function
c () 
{ 
    cd "$@" && ls --color=auto -a
}
cdd is aliased to `c ~/Downloads'
r is aliased to `. ~/.bashrc'

Based on this information, I changed the c function to d, and it works. That being said, is there any way I could not map the clear function to c as I already have alias cs='printf "\033c"' for that)? I looked in .bashrc but couldn't find anything with the word "clear".

  • Run PS4=' ${BASH_SOURCE}:${LINENO} ' bash -lixc exit |& grep clear and add the output, please. – muru Jan 30 '18 at 5:32
  • I don't seem to be getting an output. – Kevin Jan 30 '18 at 5:33
  • to remove the alias of c do unalias c, that's it. To find where that is being defined use muru command and post output: PS4=' ${BASH_SOURCE}:${LINENO} ' bash -lixc exit |& grep clear – Isaac Jan 30 '18 at 5:46
  • Probably comes from github.com/Bash-it/bash-it/blob/… – muru Jan 30 '18 at 5:54
  • Ohh. Strange though, I don't have that line in my .bashrc yet it's still aliased with every terminal launch. – Kevin Jan 30 '18 at 5:56
0

If the c is aliased to clear but not in your own shell initialization files, then it's most likely done in the system-wide initialization files under /etc. Check, for example /etc/bash.bashrc (or see your bash manual for what files are used, this may differ between systems depending on how bash was built).

No matter where c is aliased to clear, you may unalias c before defining it as a function with

unalias c

You may also consider using $HOME in place of ~. This is due to $HOME being more descriptive (and you don't actually need to type it out since it's part of an alias, so you don't "lose" anything), and that it behaves as a variable whereas ~ does not. See Why doesn't the tilde (~) expand inside double quotes?

| improve this answer | |
  • Weird. I added unalias c, but I get bash: unalias: c: not found even though it shows that it's still assigned to clear when I do type -a c cdd r. – Kevin Jan 30 '18 at 22:55
  • @Kevin Then look further down in your .bashrc file to find where the c alias gets defined or where you source a file that defines it. – Kusalananda Jan 31 '18 at 6:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.