Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Use exec to Redirect stdio in a git Hook Script


    Redirection like ls > out only applies to a single line, so how do we control bash's input and output streams for blocks of commands? exec does just that -- it changes where stdout and stderr go for all commands that come after it.

    In this lesson, we'll use exec in a script to redirect all stdout and stderr to a log file. Our script will be a post-merge git hook, which runs after a git pull is performed. It'll check git's list of changed files and run npm install if package.json was changed. Because git operations are sometimes performed inside UI instead of the shell directly, it can be handy to capture any errors in a log file.