Monday, May 6, 2024
26
rated 0 times [  26] [ 0]  / answers: 1 / hits: 2124  / 2 Years ago, thu, june 30, 2022, 8:03:26

Sorry about the non-informative heading...


What I'm looking for is something like that will allow me to shorten redirecting stdout.
I know that executing a command with whitespaces before it does not write it into history, and there are a few "magic" operators, such as "!!", etc.


I'm basically looking for something like that, that would allow me to replace >/dev/null, so, I'll be able to write, for example


git pull !!! and that would be equivalent to git pull>/dev/null


Is there something like this? Am I able to override an existing operator / write a new one?


More From » command-line

 Answers
3

Alias expansion only looks at the first token / word of a line, so there's no way for git pull !!! to get replaced by alias expansion.


However, redirects work even if placed before the command, so you can do it with an alias:


alias quiet='>/dev/null '

Leaving whitespace at the end of the alias expansion makes bash consider the next token for alias expansion. (This is why it's common to do alias sudo='sudo '). So this won't even break your aliases. Example:


$ ll *.s xyz
ls: cannot access 'xyz': No such file or directory
-rw-r--r-- 1 peter peter 12 Mar 6 20:15 a64.s
-rw-r--r-- 1 peter peter 72 Mar 6 21:03 arm.s
-rw-r--r-- 1 peter peter 30 Mar 15 17:38 foo.s
-rw-r--r-- 1 peter peter 42 Mar 6 13:12 mips.s
$ quiet ll *.s xyz # ll alias expanded successfully, stdout discarded
ls: cannot access 'xyz': No such file or directory
$ # stderr is not redirected.

[#737] Saturday, July 2, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
calronze

Total Points: 0
Total Questions: 110
Total Answers: 112

Location: Belarus
Member since Thu, Aug 11, 2022
2 Years ago
calronze questions
Sun, Jan 9, 22, 13:41, 2 Years ago
Wed, Feb 15, 23, 01:41, 1 Year ago
Sat, Jul 23, 22, 21:03, 2 Years ago
Sat, Feb 5, 22, 01:57, 2 Years ago
;