Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create an alias to a command that has spaces in it

My use case is to create an alias for opening Firefox. Usually I used Start-Process firefox.exe, which is fine. I would like, though, to just type xfirefox instead. Here is what I have tried:

Quotes

Shaun> set-alias xfirefox "Start-Process firefox.exe"
Shaun> xfirefox
xfirefox : The term 'Start-Process firefox.exe' is not 
recognized as the name of a cmdlet, function, script file, 
or operable program...

Curlies

Shaun> set-alias xfirefox { Start-Process firefox.exe }
Set-Alias : Cannot evaluate parameter 'Value' because its 
argument is specified as a script block and there is no
input. A script block cannot be evaluated without input.
like image 437
Shaun Luttin Avatar asked Oct 10 '14 00:10

Shaun Luttin


People also ask

Can alias have spaces?

This question already has answers here: All the documentation I've looked at seems to indicate that in both aliases and shell functions, the name cannot contain spaces.

What is alias in commands?

An alias lets you create a shortcut name for a command, file name, or any shell text. By using aliases, you save a lot of time when doing tasks you do frequently.


1 Answers

Aliases are just that - aliases for command names - not command names plus arguments. What you want is a function e.g.:

function xfirefox {
    Start-Process firefox.exe $args
}

Then you could launch like so:

xfirefox
xfirefox http://www.stackoverflow.com
like image 97
Keith Hill Avatar answered Oct 20 '22 00:10

Keith Hill