How to correctly do the aliasing for whois

2

I'm trying to get this alias to work.

alias awhois='whois -h whois.cymru.com " -v $1"'

But bash doesn't give the same output.

# awhois 8.8.8.8
Error: no ASN or IP match on line 1.
AS      | IP               | AS Name
15169   | 8.8.8.8          | GOOGLE - Google LLC, US

# whois -h whois.cymru.com " -v 8.8.8.8"
AS      | IP               | BGP Prefix          | CC | Registry | Allocated  | AS Name
15169   | 8.8.8.8          | 8.8.8.0/24          | US | arin     | 1992-12-01 | GOOGLE - Google LLC, US

How can I make this works? Thanks.

Kir

Posted 2017-11-15T04:26:14.773

Reputation: 23

Answers

3

Aliases don't recognize positional parameters. Use a function instead.

awhois()
{
  whois -h whois.cymru.com " -v $1"
}

Ignacio Vazquez-Abrams

Posted 2017-11-15T04:26:14.773

Reputation: 100 516

Hi, thanks! It works but when I do "source .bash_profile", it came out error.

-bash: .bash_profile: line 55: syntax error near unexpected token `(' -bash: .bash_profile: line 55: `awhois()'

Is this normal? – Kir – 2017-11-16T05:20:47.840

Are you sure you're using bash and not e.g. dash as your shell? – Ignacio Vazquez-Abrams – 2017-11-16T05:24:08.373

Yes, am using bash.

Shell: /bin/bash – Kir – 2017-11-16T05:25:43.383