Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Regexp replace on all arguments.



On Sat, Feb 11, 2006 at 11:06:26PM +0530, Ligesh wrote:
> 
>  Hi folks,
> 
>   I want to replace all occurrences of say '/c/' in the arguments with 'c:'. Could someone help me with completing the function below.
> 
>   winexec () {
> 
> 	  // First loop through all arguments and replace
> 
> 	  foreach arguments $2 to $- {
> 		  replace ^/c/ with c: , ^/d/ with d: etc. (The character c, d should be preserved, '^' means beginning of the word.)
> 	  }
> 
> 	  execute $1 with the new arguments.
> 	  
>   }
> 
>   The execution would be
> 
>   $ winexec cacls.exe /c/name-of-file
[...]

winexec() {
  local cmd=$1
  shift || return
  argv=("${@//#\/(#b)([a-zA-Z])\//$match:}")
  "$cmd" "$@"
}

-- 
Stéphane



Messages sorted by: Reverse Date, Date, Thread, Author