Did armies just walk up and dig trenches while hoping they wouldn't get hit by artillery in the process? How were these front lines formed? What were the logistics in how far they dug trenches from each other?
Yes the men would literally dig the trench on the battlefield. Typically, the enemy would already be entrenched. The attackers would come to the battlefield and make trenches. The artillery would be constantly suppressing each other. The troops would be under fire while doing it, but also be returning fire. Trenches were nearly impossible to attack head on, so you would typically have a front line trench, with reserve lines behind. The second would be the backup troops, and be 75 meters behind the first, and another one would be 300 metres back with reserve troops. They would be built in zig zag shapes to prevent an enemy who breached the trench to be able to fire right down the line. The two enemies ranged from 100 to 400 yards apart. The front line would be actively fighting, while the second would be ready if the first one should fall, while the third was mostly resting men.