I've got a command in linux which returns a list of numbers. Now I need this numbers to form a directory path and cat the file located at that path.For example:myCommand returns:1 1030 40And I want to cat all the files that look like this: /folder/1/folder2  /folder/10/folder2  /folder/30/folder2 /folder/40/folder2I Hope it is clear what I want, if not, feel free to ask.This is my code right now: myCommand | xargs catBut it obviously doesn't work since directory 1,10,30 and 40 doesn't exist.I want the output to be: the catted value - number generated by myCommand
Reuse output from command 1 in command 2 using a pipe
linux;pipe;cat
There is no problem to do thing with xargsmyCommand | xargs -I{} sh -c 'echo -n {}\ ; cat /folder/{}/folder2/file'But more syntaxically right and much flexible do it with for loop:for genpath in $(myCommand)do    echo -n $genpath\     cat /folder/$genpath/folder2/filedoneOr even through while loopwhile read genpathdo    echo -n $genpath\     cat /folder/$genpath/folder2/filedone < <(myCommand)