How can I use aliased commands with xargs?

Aliases are shell-specific - in this case, most likely bash-specific. To execute an alias, you need to execute bash, but aliases are only loaded for interactive shells (more precisely bashrc will only be read for an interactive shell) bash -i runs an interactive shell (and sources . Bashrc) bash -c cmd runs cmd Put them together: bash -ic cmd runs cmd in an interactive shell, where cmd can be a bash function/alias defined in your bashrc find -name \*bar\* | xargs bash -ic gi foo should do what you want Edit: I see you've tagged the question as "tcsh", so the bash-specific solution is not applicable.

With tcsh, you don't need the I as it appears to read . Tcshrc unless you give f Try this: find -name \*bar\* | xargs tcsh -c gi foo It worked for my basic testing.

Aliases are shell-specific - in this case, most likely bash-specific. To execute an alias, you need to execute bash, but aliases are only loaded for interactive shells (more precisely, . Bashrc will only be read for an interactive shell).

Bash -i runs an interactive shell (and sources . Bashrc). Bash -c cmd runs cmd.

Put them together: bash -ic cmd runs cmd in an interactive shell, where cmd can be a bash function/alias defined in your .bashrc. Find -name \*bar\* | xargs bash -ic gi foo should do what you want. Edit: I see you've tagged the question as "tcsh", so the bash-specific solution is not applicable.

With tcsh, you don't need the -i, as it appears to read . Tcshrc unless you give -f. Try this: find -name \*bar\* | xargs tcsh -c gi foo It worked for my basic testing.

Turn "gi" into a script instead eg, in /home/$USER/bin/gi: #! /bin/sh exec /bin/grep -i "$@" don't forget to mark the file executable.

The suggestion here is to avoid xargs and use a "while read" loop. Find -name \*bar\* | while read file; do gi foo "$i"; done See the accepted answer in the link above for refinements to deal with spaces or newlines in filenames.

If file names have blanks or newlines in them, this is not as good as xargs with -0 option (and find with -print0). – Jonathan Leffler Jun 11 '09 at 6:10 Thanks, I edited to point that out. – Pete TerMaat Jun 11 '09 at 14:05.

For tcsh (which does not have functions), you could use: gi foo `find -name "*bar*"` For bash/ksh/sh, you can create a function in the shell. Function foobar { gi $1 `find . -type f -name "*"$2"*"` } foobar foo bar Remember that using backquotes in the shell is more advantageous than using xargs from multiple perspectives.

Place the function in your .bashrc.

Using Bash you may also specify the number of args being passed to your alias (or function) like so: alias myFuncOrAlias='echo' # alias defined in your ~/. Bashrc, ~/. Profile, ... echo arg1 arg2 | xargs -n 1 bash -cil 'myFuncOrAlias "$1"' arg0 (should work for tcsh in a similar way) # alias definition in ~/.

Tcshrc echo arg1 arg2 | xargs -n 1 tcsh -cim 'myFuncOrAlias "$1"' arg0 # untested.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions