0

I'm a bit confused on how to modify the function arguements:

I want:

bower ln
bower ln thing

to execute:

bower link
bower link thing

This is as close as I have gotten:

# ~/.bashrc
bower () {
    if [[ $1 == "ln" ]]; then
        ${@[1]}="link"
        echo "replacing" "$FUNCNAME" "$@"
    fi
    command "$FUNCNAME" "$@"   
}
Ashley Coolman
  • 11,095
  • 5
  • 59
  • 81

1 Answers1

2

Use the set command:

bower () {
    if [[ $1 == ln ]]; then
        set -- link "${@:2}"
        echo "replacing $FUNCNAME $@"
    fi
    command "$FUNCNAME" "$@"
}

However, you don't really have to replace the first argument; you can simply hardcode the correct argument in the body of the if statement:

bower () {
    if [[ $1 == ln ]]; then
        echo "replacing $FUNCNAME $first $@"
        command "$FUNCNAME" link "${@:2}"
    else
        command "$FUNCNAME" "$@"
    fi
}
chepner
  • 497,756
  • 71
  • 530
  • 681