type vs which in bash

In bash, type is a shell builtin command where as which is a script.

So, using type is more preferable.

Also, some history and more.

1027 /usr/local> type which
which is aliased to `alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

1028 /usr/local> type type
type is a shell builtin

~/.bash_profile, ~/.bash_login, ~/.profile, ~/.bashrc and /etc/profile

When you log in to the system, bash will first execute the global setup file /etc/profile and then it will look for the personal setup file in the following order (will stop on the first finding)

  1. ~/.bash_profile (Derived from the Bourne Shell’s file name .profile)
  2. ~/.bash_login (Derived from the C Shell’s file name .login)
  3. ~/.profile

If all 3 files exist and need to be used, source the other files from ~/.bash_profile

~/.bashrc will be executed when you run a subshell by typing bash on the command line.

If ~/.bashrc needs to be executed when you log in to the system, source the file from ~/.bash_profile

Bash wildcards and brace expansions

Wildcards will only expand to match the names of the files in the working directory.

  • *
  • ?
  • [abc]
  • [a-z]
  • [!a-z]

So,

echo *

will list all the files in the working directory

 

But brace will expand regardless of the file existence.

echo a{b,c}d

will always echo

abd acd