LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   alias not working as expected (https://www.linuxquestions.org/questions/linux-general-1/alias-not-working-as-expected-450540/)

marozsas 06-01-2006 08:13 AM

alias not working as expected
 
Dear fellows,

I am defining an alias like this:
Code:

$ bash
$ alias test='echo prefix:$1'
$ test string
prefix: string
$

but, the expected output would be "prefix:string".

How to avoid that space after the ":" ? :scratch:

thanks in advance,

exman 06-01-2006 09:45 AM

Try this one:
Code:

alias test='echo -n prefix:;echo $1'
exman

marozsas 06-01-2006 12:17 PM

Thanks for the try, but your trick is not good. It will work only with echo.

I really need an alias "myalias argument" which is expanded to "command:argument", and what I am getting is "command: argument".

If you have any ideas why that space is inserted by the alias expansion, it will be great.

marozsas 06-01-2006 12:46 PM

solved...
 
from the bash manual:
Quote:

Originally Posted by man bash, aliases section
If arguments are needed, a shell function should be used (see FUNCTIONS below).

So, the solution is to use functions.

thanks for your time,


All times are GMT -5. The time now is 03:21 PM.