0

I've spent to much time in the DOS world where cd.. (no space) works.

I tried to do the same in ubuntu by defining a bash file in /usr/local /bin called "cl.."

its body is

#!/bin/bash
cd ..

I have chmod +x on the file.

It doesn't work, ubuntu doesn't complain about command not found.

what did I do wrong?

pomsky
  • 68,507
mfc
  • 121
  • 1
  • 3

1 Answers1

3

The unix shell scripts are quite different from DOS bat files in a sense that they are executed as separate processes, not just loading commands into current command prompt, as it is with windows cmd.exe

What you really want, is actually bash alias or function.

Both alias cd..='cd ..' and cd..() { cd ..; } will do the trick, first one defines alias, second a shell function.

In order to make it available in succeeding shells as well, it should be written in to .bash_profile, .bashrc or .profile file in your home directory. Which file exactly, depends on your distribution settings, check man bash, /etc/profile and /etc/*bashrc for details.

man bash will help you further with available commands.

If you are looking for more user-friendly shell than bash, then I suggest you to look into zsh package.

korc
  • 634
  • didn't work, I read somewhere else that ubuntu uses a .profile instead of a .bash_profile. That didn't work either. Modifying the .bashrc file as suggested by Cyrus above worked. Thanks. – mfc Sep 13 '15 at 01:31
  • .bash_aliases would have been a better choice for this purpose. – Gunnar Hjalmarsson Sep 13 '15 at 01:41
  • Not even ~/.bash_aliases IMO. ~/.bash_aliases AFAIK is used for aliases added by external programs. The correct way to add user-defined aliases IMO is to add them to ~/.bashrc – kos Sep 13 '15 at 02:55
  • @kos: Never heard that. Quoting a comment in /etc/skel/.bashrc: "Alias definitions. You may want to put all your additions into a separate file like ~/.bash_aliases, instead of adding them here directly." – Gunnar Hjalmarsson Sep 13 '15 at 06:37
  • @GunnarHjalmarsson Yes, I didn't mean that's wrong at all, let me rephrase it: I'd put it into ~/.bashrc, because that way you can keep aliases added by you separated from aliases added by external programs, with the easiness, e.g., of backing them up without keeping broken aliases; ~/.bash_aliases is perfectly fine as well tough – kos Sep 13 '15 at 08:09
  • @GunnarHjalmarsson .bash_aliases is not a file processed by bash itsself, but generally just sourced from .bashrc or .bash_profile, and meant for people who have many aliases and want to save them with alias >~/.bash_aliases – korc Sep 13 '15 at 09:34
  • ~/.bash-aliases is, as far as I know, an Ubuntu-only feature. The normal place for aliases is ~/.bashrc. – terdon Sep 13 '15 at 13:40