How to pipe a text file containing mongod arguments to mongod command

Solution 1:

Ubuntu , and all Linux distributions with GNU utilities installed, have xargs , which allows running a command with arguments piped from another command or from provided from stdin. In your case , what you would want to do is the following:

xargs  mongod < mongo_args.txt

Here you have mongo_args.txt which is the text file with your arguments, and it's being redirected as stdin to xargs. That will be joined together with mongod and ran as complete command.

Solution 2:

You're on the right path, but you're trying to pipe the output of cat mongod.txt. Piping doesn't mean the output will get added as the arguments. Instead, when you pipe data, the receiving program has to know how to deal with the pipe'd data.

For example if we have banana.txt with the text Test:

  1. cat banana.txt | echo
    • Empty line as output
  2. echo "$(cat banana.txt)"
    • Test as output

Instead of piping, we're asking bash to evaluate cat banana.txt, and insert that there immediately, and before executing echo.

While there are thousands of actual examples, a few examples of where you would want to pipe would be with tools like grep and sed, and dd. Look into 'bash piping', 'bash evaluation/expansion', and stuff like STDIN.