Last Updated: February 25, 2016
·
4.241K
· blake barrett

shell function arguments in bash/os x

I love the alias keyword in bash, but when it comes to passing in multiple arguments, you really need a function.
Arguments passed to functions are accessible via $1, $2, $N, …

Lets see this in use:

function backup() {
rsync $1 -rvhzI --size-only --inplace --human-readable --compress --compress-level=1 $2 ;
}

This function takes two arguments, the first is the source folder the second is the target or destination folder which get passed to the rsync command via arguments passed when calling the backup function; like so:

backup ~ /Volumes/NAS/MyUserFolderBackup/

http://blog.blakebarrett.net/2012/07/backup-command-in-osx-terminal.html