52
votes
Accepted
Would globally aliasing the fork bomb prevent its execution?
The two, no, three, ... Amongst the main obstacles to that are:
It's not a valid name for an alias. Bash's online manual:
The characters ... and any of the shell metacharacters or quoting ...
40
votes
Accepted
Are there any single character bash aliases to be avoided?
Things to avoid:
standard or common commands with single character names: w (show logged in users' activity), X (X Window System server), R (R programming language interpreter), [ (similar to test)
...
38
votes
Accepted
How to make a multiline alias in Bash?
It's not impossible at all.
alias thing='(
cd "${program_to_update_dir}"
wget "https://raw.githubusercontent.com/USER/PROJECT/BRANCH/update.sh"
source update.sh
rm update.sh
)'
or,...
29
votes
Accepted
How to create an environment variable that is the output of a command
In general the sequence foo="$(bar)" will run the command bar and assign the output to the variable.
e.g.
% echo $PWD
/home/sweh
% BWD="$(basename "$PWD")"
% echo $BWD
sweh
This creates a shell ...
28
votes
Accepted
How to make `python` an alias of `python3` systemwide on Debian
It looks like Debian is now shipping python-is-python3 themselves (in Debian 11 and later), so the premise of the question no longer holds and you can just: sudo apt update && sudo apt install ...
27
votes
Accepted
How can I alias `...` to `../..` in Bash?
If switching to zsh is an option, you could use global aliases there for that:
alias -g ...=../..
But in any case that's only expanded when ... is recognised as a full delimited token on its own. It ...
24
votes
Making alias of rm command
An alias can not take arguments and use $@ to access them like that.
Alias expansion in bash is a simple text replacement. If you have alias rm ='something something', then using rm file1 file2 would ...
23
votes
Accepted
nohup: failed to run command `.': Permission denied
nohup runs an executable. You need to pass it an external command, i.e. an executable file. You can't call nohup on a shell construct such as an alias, function or builtin. nohup runs a new process, ...
23
votes
Accepted
-bash: /bin/cd: No such file or directory - automatically execute ls after cd
Your system (like many Unix systems) does not have an external cd command (at least not at that path). Even if it had one, the ls would give you the directory listing of the original directory. An ...
22
votes
How do I get bash completion for command aliases?
By googling this issue, I ended up here, so I tried the approaches in the other answers. For various reasons I don't actually understand, they never behaved properly in my Ubuntu 16.04.
What in the ...
22
votes
Accepted
bash aliases do not expand even with shopt expand_aliases
It doesn't seem work if you set the alias on the same line as it's used. Probably something to do with how aliases are expanded really early in the command line processing, before the actual parsing ...
22
votes
Accepted
Multi-word aliases in bash
Well, I get:
$ alias 'apt update'='sudo apt update -y'
bash: alias: 'apt update': invalid alias name
which seems clear enough.
Similarly, you can't have functions or commands with whitespace in their ...
21
votes
Why doesn't my Bash script recognize aliases?
You can also use . before your script. Run it as:
. /path/to/your/script.sh
You can check for this condition on your bash script as follows:
if [[ $- == *i* ]]
then
echo "running on ...
21
votes
Accepted
Multiples aliases for one command
You could use brace expansion.
alias {name1,name2}="echo hello"
or for your example
alias lw{p,b}c="$(npm bin)/webpack"
https://www.gnu.org/software/bash/manual/html_node/Brace-...
21
votes
Are there any single character bash aliases to be avoided?
The simplest way is probably to check whether something with that name already exists. On my system:
$ for char in {A..z}; do type "$char" 2>/dev/null; done
R is /usr/bin/R
X is /usr/bin/...
20
votes
Accepted
why doesn't gdb like aliases
Aliases are a feature of the shell. Defining an alias creates a new shell command name. It's recognized only by the shell, and only when it appears as a command name.
For example, if you type
> ...
20
votes
Accepted
Bash shadow a command - function with same name as command
Any character in front of an alias will prevent the alias from triggering:
alias ls='ls -la'
ls foo.txt #will run ls -la foo.txt
\ls foo.txt #will run ls foo.txt
'ls' foo.txt #will run ls foo....
20
votes
Accepted
How to overwrite aliases in my shell (Oh My Zsh)?
The alias command overrides a previous alias by the same name. So generally, if you want your aliases to override the ones defined by a zsh framework, put them at the end of your .zshrc. The same goes ...
19
votes
How to create alias for ssh command?
I usually use the .ssh/config file found in my home directory to run my OpenSSH client in the format ssh ubserver. In that file found here /home/$USER/.ssh I have the follow configurations:
Host ...
18
votes
How to create alias with a command contains ' and "
Saying that the syntax of an alias is alias aliasname='command' is a bit misleading, as it seems to imply that the single quotes are part of the syntax. They are not. The part after the equal sign is ...
18
votes
How to create an environment variable that is the output of a command
In Bourne-like shells, you create environment variables by marking a shell variable with the export attribute (so it's exported to the environment of the commands that the shell will execute) by using ...
18
votes
bash aliases do not expand even with shopt expand_aliases
Turning my comment into an answer, as suggested by ilkkachu.
The Bash manual (linked to in the question) does provide an explanation of how the aliases are handled when there is an alias definition ...
18
votes
Accepted
How to use aliases with `watch` command?
aliases are enabled in interactive shells, so try this:
watch -x bash -ic "my-alias"
# .............^
17
votes
watch command alias expansion
Maybe we could manually expand the alias before watch sees it?
watch $(alias ll | cut -d\' -f2)
Explanation
The output of alias ll looks like:
$ alias ll
alias ll='ls -lAGh'
So we set cut's ...
17
votes
How to turn globbing on and off?
If you want globs to be disabled only while the shell is interpreting code in any.sh, with bash4.4+ or ash-based shells, you can do:
x() {
local -
set -o noglob
. any.sh
}
Or in zsh:
x() {
...
17
votes
Accepted
Where is the script for alias command in Linux?
alias is a builtin command, so it doesn't show up as script in any file, or as a function. The type command will show this:
$ type alias
alias is a shell builtin
But you can still override it. A ...
17
votes
Would globally aliasing the fork bomb prevent its execution?
No. There are just too many ways to write a fork-bomb.
The evil fork-bomb writer will just try again with a different function name. Or other alterations until his fork-bomb succeeds.
The ...
17
votes
Are there any single character bash aliases to be avoided?
Addressing: "I'm curious if this should be avoided."
As described in the other answers, there should be no technical problem as long as the command you are overriding with the alias it isn't ...
16
votes
How can I test if a particular alias is defined?
I’m gonna make @jimmij’s comment from 5 years ago into an answer:
type -t is designed for exactly that purpose. It will output alias if the given command is an alias. If the command does not exist, it ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
alias × 927bash × 517
shell × 166
zsh × 122
shell-script × 67
function × 53
linux × 52
command-line × 52
quoting × 35
ssh × 30
cd-command × 25
tcsh × 24
sudo × 22
csh × 21
macos × 20
scripting × 19
oh-my-zsh × 18
grep × 17
terminal × 17
environment-variables × 16
command × 16
autocomplete × 16
vim × 15
command-history × 15
ubuntu × 14