1

How to make alias that take argument and interpolate it to file extension to create it? I tired this and this doesn't work :

alias create-bash-file=' echo  "#!/bin/bash" > "$1.sh" '

as $1 is first argument and .sh is file extension and I wanted to make an alias that create a bash file included "#!/bin/bash" but the file name I want to take it as an argument so for example and I will write create-bash-file filename this should generate bash file called filename.sh

Cyrus
  • 84,225
  • 14
  • 89
  • 153

1 Answers1

5

Aliases don't take arguments; functions do.

create-bash-file () {
    echo "#!/bin/bash" > "$1.sh"
}
chepner
  • 497,756
  • 71
  • 530
  • 681
  • Thanks it works but when I try to interpolate the argument to an url for example a git repo it's does work... functionName() { "git@github.com:user/$1.git"} – Khaled Developer Nov 28 '21 at 18:12
  • 1
    @KhaledDeveloper In that example, you need the `echo` command, and a semicolon or line break before the `}`. – Gordon Davisson Nov 28 '21 at 18:47