Search code examples
linuxcommand-lineubuntunestedsolaris

Can I execute nested or chained commands in UNIX shell?


Can I execute command within another command in UNIX shells?

If impossible, can I use the output of the previous command as the input of next command, as in:

command x then command y,

where in command y I want use the output of command x?


Solution

  • What exactly are you trying to do? It's not clear from the commands you are executing. Perhaps if you describe what you're looking for we can point you in the right direction. If you want to execute a command over a range of file (or directory) names returned by the "find" command, Colin is correct, you need to look at the "-exec" option of "find". If you're looking to execute a command over a bunch of arguments listed in a file or coming from stdin, you need to check out the "xargs" commands. If you want to put the output of a single command on to the command line of another command, then using "$(command)" (or 'command' [replace the ' with a backquote]) will do the job. There's a lot of ways to do this, but without knowing what it is you're trying it's hard to be more helpful.