0

I'm transitioning to a new development environment for work, and I'm new to the xterm terminal and the CentOS operating system.

I'm trying to set up aliases in my .bashrc:

# .bashrc
alias c='clear'
alias la='ls -a'

But only the c alias works:

user@host:~> la
CORRECT>lua (y|n|e|a)? no
la: Command not found.

but user@host:~> c successfully clears the terminal. I tried defining several other aliases as well (directly in the interactive terminal) and only the c='clear' alias worked. Why might some aliases work while others don't?

  • @steeldriver That's not zsh, it's tcsh. The zsh autocorrect prompt could be configured to look like tcsh's, but the "command not found" message couldn't. With zsh, .bashrc would have no effect but interactive alias definitions would work. – Gilles 'SO- stop being evil' Apr 17 '20 at 19:14
  • @Gilles'SO-stopbeingevil' ah thanks - right idea, wrong shell ;) – steeldriver Apr 17 '20 at 19:16
  • Have you already tried debugging it (which, type): https://unix.stackexchange.com/questions/109216/l-ls-la-what-are-the-differences-and-are-there-more-of-these-commands Your alias-syntax seems correct. – motzmann Apr 17 '20 at 18:55
  • I only have ls, not la or l, according to which. I used the la=ls -a as a minimum working example, but also tried other aliases involving cd and other commands. c='clear' was the only alias that worked. – Jacob Stern Apr 17 '20 at 19:18
  • And what does type -a la print? (Mentioned in the answer I linked.) Or: nevermind, see the answer above and switch from tcsh – I'm too young to know this. – motzmann Apr 17 '20 at 19:26

1 Answers1

5

This prompt shows that you're running tcsh. Your aliases in .bashrc have no effect because tcsh doesn't (and can't) read bash's configuration files. Your attempts to define an alias on the command line have no apparent effect because tcsh also has a command called alias, but its syntax is a little different from bash. c is working because your (t)csh configuration happens to also have the same alias.

You probably didn't intend to use tcsh. It was the best interactive shell in the 1980s, but zsh caught up and overtook it in the 1990s, and so did bash in the 2000s. Switch to /bin/zsh or /bin/bash as your login shell:

chsh -s /bin/bash

If you can't run chsh due to administrative restrictions, see Changing the default shell without chsh or administrator privileges.

If you absolutely have to use tcsh because you absolutely need login scripts that depend on it and your administrator is living in the 1990s and won't update them, you can still use a different interactive shell. Put something like

setenv SHELL /bin/bash

in your .login (that's the file that tcsh reads when you log in).

  • Thanks! 1: You're right that I was using tcsh. 2. I tried chsh... but can't, due to administrative restrictions (though I do have /bin/bash). 3. Re: the link, I changed the default shell by adding the suggested snippet to .login, with a few modifications. I changed usr/local/bin/bash to /bin/bash in both cases, I deleted . ~/.profile; and added the --login flag to the bash command. This worked! 4. FYI, I added setenv SHELL /bin/bash to .login, and it had no effect -- when I started a new terminal, I landed directly in a tcsh environment again. – Jacob Stern Apr 17 '20 at 20:09
  • @JacobStern Changing .login doesn't change anything immediately, only when you log in. There's no reason to delete ~/.profile. – Gilles 'SO- stop being evil' Apr 17 '20 at 21:30
  • And for sanity find out about the difference between a shell, and a terminal. And upgrade from xterm. It was OK in the 1980's. – ctrl-alt-delor Apr 17 '20 at 21:35
  • @ctrl-alt-delor There's nothing wrong with xterm. Other terminal emulators don't do much that it doesn't do, and it does things that most other terminal emulators don't do (such as the ability to distinguish all key sequences, which terminals based on libvte don't have). It's maintained (two releases in 2020 so far). In contrast, tcsh doesn't do anything that zsh doesn't do, doesn't do much that bash doesn't do, doesn't do a lot that bash and zsh do. Ok, it does look like someone is maintaining it these days. But I still don't see any reason to recommend it to a new user. – Gilles 'SO- stop being evil' Apr 18 '20 at 07:49