How to intercept and remove a command line argument in bash How to intercept and remove a command line argument in bash shell shell

How to intercept and remove a command line argument in bash


This should work:

# Run older ld (pseudo condition)if [ <old_ld_condition> ]; then    ARGS=()    for var in "$@"; do        # Ignore known bad arguments        [ "$var" != '-dependency_info' ] && ARGS+=("$var")    done    /path/to/old/ld "${ARGS[@]}"else    /path/to/new/ld "$@"fi


You should use Bash Arrays if you really want to stay with bash:

declare -a ARGSfor var in "$@"; do    # Ignore known bad arguments    if [ "$var" = '-dependency_info' ]; then        continue    fi    ARGS[${#ARGS[@]}]="$var"done

now "${ARGS[@]}" can be used just as "$@". man bash for more information.