How can I use a parameter with an alias?
by dave555 from LinuxQuestions.org on (#4Y6C0)
Hello
I need a little help with this. I am making an alias to create a password quickly.
This works:
Code:alias makepw="cat /dev/urandom | tr -cd '[:alnum:]%$#-' | head -c 15 ; echo"
~ % makepw
9oFpSu4N%5VDIYFHowever, when I change to head -c $1, I get this error
Code:alias makepw="cat /dev/urandom | tr -cd '[:alnum:]%$#-' | head -c $1 ; echo"
~ % makepw 19
head: option requires an argument -- 'c'
Try 'head --help' for more information.
19I'm trying to use $1 as an argument to pass different lengths for a password.
PS: The command without the alias part works fine if used in it's own shell script file, BUT I want to use it as an alias in my .bashrc file.
Any ideas what I am doing wrong? Thanks in advance


I need a little help with this. I am making an alias to create a password quickly.
This works:
Code:alias makepw="cat /dev/urandom | tr -cd '[:alnum:]%$#-' | head -c 15 ; echo"
~ % makepw
9oFpSu4N%5VDIYFHowever, when I change to head -c $1, I get this error
Code:alias makepw="cat /dev/urandom | tr -cd '[:alnum:]%$#-' | head -c $1 ; echo"
~ % makepw 19
head: option requires an argument -- 'c'
Try 'head --help' for more information.
19I'm trying to use $1 as an argument to pass different lengths for a password.
PS: The command without the alias part works fine if used in it's own shell script file, BUT I want to use it as an alias in my .bashrc file.
Any ideas what I am doing wrong? Thanks in advance