Skip to main content
added 97 characters in body
Source Link
Mikel
  • 58.7k
  • 16
  • 136
  • 155

If it should be very fast, make it an alias or a function.

If it should be usable outside your preferred shell, make it a script.1

If it takes arguments, make it a function or a script.

If it needs to contain special characters, make it an alias or a script.2

If it needs to work with sudo, make it an alias or a script.3

If you want to change it easily without logging out and in, a script is easier.4

Footnotes

1 Or make it an alias, put it in ~/.env and set export ENV="$HOME/.env", but it's complicated to make it work portably.

2 Function names must be identifiers, so they must start with a letter, and may only contain letters, digits, and underscores. For example, I have an alias alias +='pushd +1'. It can't be a function.

3 And add the alias alias sudo='sudo '. Ditto any other command such as strace, gdb, etc. that takes a command as its first argument.

4 See also: fpath. Of course you can also do source ~/.bashrc or similar, but this often has other side effects.

If it should be very fast, make it an alias or a function.

If it should be usable outside your preferred shell, make it a script.1

If it takes arguments, make it a function or a script.

If it needs to contain special characters, make it an alias or a script.2

If it needs to work with sudo, make it an alias or a script.3

If you want to change it easily without logging out and in, a script is easier.4

Footnotes

1 Or make it an alias, put it in ~/.env and set export ENV="$HOME/.env", but it's complicated to make it work portably.

2 Function names must be identifiers, so they must start with a letter, and may only contain letters, digits, and underscores. For example, I have an alias alias +='pushd +1'. It can't be a function.

3 And add the alias alias sudo='sudo '. Ditto any other command such as strace, gdb, etc. that takes a command as its first argument.

4 See also: fpath.

If it should be very fast, make it an alias or a function.

If it should be usable outside your preferred shell, make it a script.1

If it takes arguments, make it a function or a script.

If it needs to contain special characters, make it an alias or a script.2

If it needs to work with sudo, make it an alias or a script.3

If you want to change it easily without logging out and in, a script is easier.4

Footnotes

1 Or make it an alias, put it in ~/.env and set export ENV="$HOME/.env", but it's complicated to make it work portably.

2 Function names must be identifiers, so they must start with a letter, and may only contain letters, digits, and underscores. For example, I have an alias alias +='pushd +1'. It can't be a function.

3 And add the alias alias sudo='sudo '. Ditto any other command such as strace, gdb, etc. that takes a command as its first argument.

4 See also: fpath. Of course you can also do source ~/.bashrc or similar, but this often has other side effects.

Source Link
Mikel
  • 58.7k
  • 16
  • 136
  • 155

If it should be very fast, make it an alias or a function.

If it should be usable outside your preferred shell, make it a script.1

If it takes arguments, make it a function or a script.

If it needs to contain special characters, make it an alias or a script.2

If it needs to work with sudo, make it an alias or a script.3

If you want to change it easily without logging out and in, a script is easier.4

Footnotes

1 Or make it an alias, put it in ~/.env and set export ENV="$HOME/.env", but it's complicated to make it work portably.

2 Function names must be identifiers, so they must start with a letter, and may only contain letters, digits, and underscores. For example, I have an alias alias +='pushd +1'. It can't be a function.

3 And add the alias alias sudo='sudo '. Ditto any other command such as strace, gdb, etc. that takes a command as its first argument.

4 See also: fpath.