Create new folder and text file the same time in one line

Is it possible to create new folder and write a new text file in the folder while the current position is outside the new folder? in one line

mkdir folder | echo "hello test"> folder/test.txt

not work.

The pipeline | is for conveying one process' stdout to another process' stdin. Neither does mkdir print anything to stdout, nor does echo read from stdin. So - above pipe is pointless. Try

mkdir -p folder && echo "hello test"> folder/test.txt

echo only if mkdir succeeds.

1 Like