Re: How to get argv[0] in alias for bashrc



On 2006-09-27, 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.

In a POSIX shell, an alias is a simple substitution; the alias is
replaced with the exact string it is defined as. (Variables will
be expanded when the alias is used, if they were single-quoted,
but the positional parameters will refer to the existing
parameters, not arguments.)

In bash, "For almost every purpose, aliases are superseded by
shell functions."

transfer()
{
wget "http://www.$1/temp/transfer.gz";
}

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
.



Relevant Pages

  • Re: Back to last driectory
    ... thing to do would be to modify the shell itself to add a directory stack ... as well as a command stack and modify the "cd" command to accept ... I alias cd to chdir which is a function ... The trailing space tells the shell to check the next word for an alias so ...
    (comp.unix.shell)
  • Re: newbie questions
    ... > from a remote host the alias is made but when i log in x it is not. ... As shell i use bash. ... It sounds as if the window manager is invoking the ... "xterm -ls" and see if your alias settings are being read. ...
    (freebsd-questions)
  • Re: How to set /etc/fstab again after system has started
    ... on a Linux desktop somewhere. ... that shell prompt become somewhat more important. ... For me, the big one is "select", which allows any shell command or alias ...
    (comp.os.linux.misc)
  • Re: How to set /etc/fstab again after system has started
    ... on a Linux desktop somewhere. ... that shell prompt become somewhat more important. ... For me, the big one is "select", which allows any shell command or alias ...
    (comp.os.linux.misc)
  • Re: Can u tell me the explanation reg this problem
    ... was provided to the exec*() system call ... ... The program "name" might turn out to be a shell alias that ... A shell *could* choose to ... supply the alias, without exporting it. ...
    (comp.lang.c)