2

Suppose I entered the following thing into terminal:

wgets "link"

I will get the response:

No command 'wgets' found, did you mean: Command 'wget' from package 'wget' (main)

I made a mistake, and the terminal warned me.

Is there a command that I can type after the terminal warned me, so that then it will execute the command above with what it thought it was?

For example:

->wgets "link" ->No command 'wgets' found, did you mean: Command 'wget' from package 'wget' (main) ->yes (this command I am looking for ... is there one?) -> executing wget "link" 
10
  • 1
    This is not a generic "shell" question. What happens in this circumstance varies from shell to shell. The Z shell differing from the Bourne Again shell differing from the Korn shell, for example. It also depends from what shell extensions are installed. Your question is describing the behaviour of a particular shell with a particular extension. Commented Jun 23, 2017 at 20:39
  • I don't have much knowledge of Linux, so feel free to remove tags you don't think are valid here Commented Jun 23, 2017 at 20:40
  • 1
    In most cases, people take advantage of the respective shells history file here. Use the Up Arrow to type a repeat of the command, remove the mistake, and continue Commented Jun 23, 2017 at 20:46
  • @eyoung100 I'm aware of that, that's why I've been doing until now :P Commented Jun 23, 2017 at 20:51
  • 3
    I think you want thefuck. ;) I wouldn't use it in Production in a million years, but it's funny. Commented Jun 23, 2017 at 22:19

3 Answers 3

4

In Bash you can use search and replace to modify the previously run incorrect command. From your example:

->wgets "link" ->No command 'wgets' found, did you mean: Command 'wget' from package 'wget' (main) ->^wgets^wget^ 

The wgets will be replaced with wget and the command executed.

To facilitate this on a command from earlier in the history list:

->!wgets:s/wgets/wget/ 

From man 3 history under Event Designators:

!string Refer to the most recent command starting with string. ... ^string1^string2^ Quick Substitution. Repeat the last command, replacing string1 with string2. Equivalent to ''!!:s/string1/string2/''. 
1

Switch to zsh (installed by default on macOS and available as a package on all major Linux distributions, *BSD, and software collections for other Unix-like operating systems). It has autocorrect for command names.

% wgets zsh: correct 'wgets' to 'wget' [nyae]? y wget: missing URL … 
1

As Wildcard already suggested install thefuck and then alias "yes" to it by adding the following lines to your .bash_profile, .bashrc or .zshrc:

eval $(thefuck --alias) alias yes="fuck" 
->wgets "link" ->No command 'wgets' found, did you mean: Command 'wget' from package 'wget' (main) ->yes -> wget "link" [enter/↑/↓/ctrl+c] -> Downloading... 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.