bashshellaliasespositional-parameter

Take first argument from alias command and interpolate it to file name extension


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


Solution

  • Aliases don't take arguments; functions do.

    create-bash-file () {
        echo "#!/bin/bash" > "$1.sh"
    }