0

Looking over the Dokku source code, I noticed two uses of pipe and redirect that I am not familiar with.

One is: cat | command

Example: id=$(cat | docker run -i -a stdin progrium/buildstep /bin/bash -c "mkdir -p /app && tar -xC /app")

The other is cat > file

Example: id=$(cat "$HOME/$APP/ENV" | docker run -i -a stdin $IMAGE /bin/bash -c "mkdir -p /app/.profile.d && cat > /app/.profile.d/app-env.sh")

What is the use of pipe and redirect in the two cases?

ustun
  • 6,941
  • 5
  • 44
  • 57

1 Answers1

1

Normally, both usages are completely useless.

cat without arguments reads from stdin, and writes to stdout.

cat | command is equivalent with command.

&& cat >file is equivalent with >file, assuming the previous command processed the stdin input.

Looking at it more closely, the sole purpose of that cat command in the second example is to read from stdin. Without it, you would redirect the output of mkdir to the file. So the command first makes sure the directory exists, then writes to the file whatever you feed to it through the stdin.

Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176
  • OK, it seems like these usages are partially due to the author's ignorance, but your second point might be key. – ustun Oct 01 '13 at 11:39
  • I wonder why this wouldn't work, maybe I'm looking over something: id=$(docker run -i -a stdin $IMAGE /bin/bash -c "mkdir -p /app/.profile.d && cat "$HOME/$APP/ENV" > /app/.profile.d/app-env.sh") – ustun Oct 01 '13 at 11:44