Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.bash_profile alias with variables [duplicate]

Tags:

bash

shell

I'm trying to create an alias that will create a file and open it in VS Code.

Create an alias called create <filename> that will execute touch <filename> && code <filename>.

For example create app.js should execute touch app.js && code app.js.

like image 302
Milad Avatar asked Jul 18 '26 20:07

Milad


1 Answers

From man bash, under ALIASES:

There is no mechanism for using arguments in the replacement text. If arguments are needed, a shell function should be used (see FUNCTIONS below)."

Thus:

create() { touch "$1"; code "$1"; }
like image 167
Amadan Avatar answered Jul 20 '26 17:07

Amadan