I want to create an alias for xfreerdp, and I need to concatenate the /v: parameter in my alias with the server name, that I'm obviously providing when invoking this alias.


alias r='xfreerdp /u:user /p:password /w:1300 /h:768 /sec:rdp /cert-ignore +cliprdr --plugin rdpsnd --plugin rdpdr --data disk:media:/tmp/RDP /v:'


r mywindows.server.com


tcp_connect: getaddrinfo (Não há endereço associado com o nome) Error: protocol security negotiation or connection failure

Is there a way to concatenate your bash alias with the next parameter?

Thank you in advance.


The problem is that the alias is being expanded and executed before the next argument is reached, hence the server name is not being concatenated to the expanded alias.

In these kind of cases, you need to use a function:

r_d () { 
xfreerdp /u:user /p:password /w:1300 /h:768 /sec:rdp /cert-ignore +cliprdr --plugin rdpsnd --plugin rdpdr --data disk:media:/tmp/RDP /v:"$1"

Now you can do:

r_d server.foobar.com
  • That's odd, since my old xfreerdp version alias was "alias r: xfreerdp --u user --p password --h" and it was accepting my servername as parameter. Unfortunately, this way is not supported anymore. – Carlos Eduardo Santos Oct 26 '15 at 12:07

You cannot give aliases parameters, BUT you can trick it with xargs, or more specifically it's flag -I, which allows replacing string. In this example I am replacing telling it to replace REPLACESTRING with whatever xargs receives.

Edited alias:

alias r='xargs -I REPLACESTRING  xfreerdp /u:user /p:password /w:1300 /h:768 /sec:rdp /cert-ignore +cliprdr --plugin rdpsnd --plugin rdpdr --data disk:media:/tmp/RDP /v:REPLACESTRING'

Note: notsure how your xfreerdp command works,I noticed other flags such as /p:password leave no spaces between the flag and the data field, so adjust /v: and REPLACESTRING spacing as you feel necessary.

Run like so:

r <<< "server.somedomain.com"


echo "server.somedomain.com" | r
  • Nice trick! Worked like a charm! Using a function to provide a parameter works too, and saves me two or three characters, but your solution is closer to what I asked. – Carlos Eduardo Santos Oct 26 '15 at 12:04

Use function as alias instead of command only. Then you can use parameter in function's body as it is described in another answer.

  • Your answer agrees with @heemayl 's one, and also works. Thank you! – Carlos Eduardo Santos Oct 26 '15 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.