Re: How to get argv[0] in alias for bashrc
- From: kiat.huang@xxxxxxxxx
- Date: 27 Sep 2006 01:39:43 -0700
veg_all@xxxxxxxxx wrote:
any clues how i can get alias to accept the ARGV[0] which is the first
command line argument:
# .bashrc
alias transfer='wget "http://www.$ARGV[0]/temp/transfer.gz"';
When I run it I get:
--22:03:20-- http://www.%5C044argv%5B0%5D/temp/transfer.gz
=> `transfer.gz'
Resolving www.\044argv[0]... failed: Name or service not known.
I looked into this once or twice and no go - the way to do it is from a
simple script, say in ~/bin
<snip>From the bash manual
There is no mechanism for using arguments in the replacement
text. If
arguments are needed, a shell function should be used (see
FUNCTIONS
below).
</snip>
For what you want to do, this would work:
[khuang@xxxxxxxxxxxx ~]$ chmod +x bin/transfer
[khuang@xxxxxxxxxxxx ~]$ cat ~/bin/transfer
#!/bin/bash
wget http://www.${1}/temp/transfer.gz
[khuang@xxxxxxxxxxxx ~]$ transfer google.com
--09:38:46-- http://www.google.com/temp/transfer.gz
=> `transfer.gz'
Resolving www.google.com... 66.102.9.104, 66.102.9.99, 66.102.9.147
Connecting to www.google.com|66.102.9.104|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
09:38:51 ERROR 404: Not Found.
[khuang@xxxxxxxxxxxx ~]$
.
- References:
- How to get argv[0] in alias for bashrc
- From: veg_all
- How to get argv[0] in alias for bashrc
- Prev by Date: Re: Filesystem usage by Directory wise
- Next by Date: Grep can find a pattern in a text, but not in a file
- Previous by thread: Re: How to get argv[0] in alias for bashrc
- Next by thread: Grep can find a pattern in a text, but not in a file
- Index(es):
Relevant Pages
|