Reputation: 13
I have used the command alias filecreate='touch $1'
in my script to create a new file in my present working directory with the help of filecreate as custom command. But when I execute the script it's showing error. Also how do I make the command to accept 2 parameters one the filename and other the pathname.
Upvotes: 0
Views: 57
Reputation: 60068
alias filecreate=touch
or its function equivalent:
filecreate(){ touch "$@"; }
will accept an arbitrary number of arguments and pass them to touch
.
Positional argument expansions usually don't belong in aliases, as aliases, unlike functions, don't get their own positional argument arrays. Aliases are simple text expansions.
Your
alias filecreate='touch "$1"'
when run like so:
filecreate SomeFile
would simply expand to
filecreate "$1" SomeFile #$1 comes from the caller
This differs from functions and scripts, which do get their own argument array.
Upvotes: 3