Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Some friendly shell-scripting hints!

— Quoted strings continue until the close quote, regardless of intervening newlines, tabs or spaces. Your REPOS definition would be more readable without the backslashes and work just as well:

  REPOS="
    $HOME/git/repo1
    $HOME/git/repo2
    $HOME/git/repo3
    "
— pushd and popd are handy, but are bash extensions and not part of POSIX /bin/sh (and yes, a lot of systems including Ubuntu and Debian have a bare POSIX /bin/sh). Even when they are available, shell error handling can make it difficult to be sure that each pushd has a matching popd. A simpler approach is to just cd in the subshell:

  sh -c "cd $REPO; $1"
— Rather than explicitly invoking the shell you might find it easier to do the same thing with syntax:

  (
    cd $REPO
    eval "$1"
  )
...or, you might find that even less readable. Up to you!


No need. "git --git-dir $REPO/.git --work-tree $REPO <command>" is (almost) exactly equivalent to cd-ing to the work tree.


Thanks for the tips.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: