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

Because I can can never remember to use pigz I have to have this in my dotfiles:

  function ccm() {
    tar -cf - $1 | pigz > $1.tar.gz
  }


Okay, I feel that my first response was too snarky. I'm sorry. In its place, I'll say:

You wouldn't go outside without pants. You shouldn't use a variable without quotes. Put pants on all variables. Also, you shouldn't use () with 'function' it "works" in Bash but it's not standard:

  ccm() {
    tar c "${1}" | pigz > "${1}.tar.gz"
  }
You could further improve it with a loop to accept multiple files:

  ccm() {
    for i in $@; do
      tar c "${i}" | pigz > "${i}.tar.gz"
    done
  }
Now you can run it like: `ccm file1 file2 file3`

See: https://mywiki.wooledge.org/Quotes

See: https://mywiki.wooledge.org/BashGuide/CompoundCommands#Funct...


Good thing you never use file names with spaces ;)




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

Search: