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 names... or well, you could, but you'd have to escape the space when using them, not fun.
The simple workaround would be to use another name instead, e.g. this should work:
alias apt-update='sudo apt update -y'
Or if you really want to, you could make apt
a function that checks the second word (first argument) too. This should turn apt update foo
into sudo apt update -y foo
, just like the alias would; and would run any other commands as they were:
apt() {
if [ "$1" = "update" ]; then
shift # eat the 'update'
sudo apt update -y "$@"
else
command apt "$@"
fi
}
(Of course apt update
doesn't take arguments, but you might want to be able to pass them for some other similar ones.)