Skip to main content
deleted 7 characters in body
Source Link
AgileZebra
  • 583
  • 6
  • 16

Found this when looking to separate the last argument from all the previous one(s). Whilst some of the answers do get the last argument, they're not much help if you need all the other args as well. This works much better:

heads=${@:1:$(($# - 1))}
tail=${@:$#}

Note that this is bash-only.

Found this when looking to separate the last argument from all the previous one(s). Whilst some of the answers do get the last argument, they're not much help if you need all the other args as well. This works much better:

heads=${@:1:$(($# - 1))}
tail=${@:$#}

Note that this is bash-only.

Found this when looking to separate the last argument from all the previous one(s). Whilst some of the answers do get the last argument, they're not much help if you need all the other args as well. This works much better:

heads=${@:1:$#-1}
tail=${@:$#}

Note that this is bash-only.

added 28 characters in body
Source Link
oguz ismail
  • 49.2k
  • 16
  • 53
  • 75

Found this when looking to separate the last argument from all the previous one(s). Whilst some of the answers do get the last argument, they're not much help if you need all the other args as well. This works much better:

heads=${@:1:$(($# - 1))}
tail=${@:$#}

Note that this is bash-only.

Found this when looking to separate the last argument from all the previous one(s). Whilst some of the answers do get the last argument, they're not much help if you need all the other args as well. This works much better:

heads=${@:1:$(($# - 1))}
tail=${@:$#}

Found this when looking to separate the last argument from all the previous one(s). Whilst some of the answers do get the last argument, they're not much help if you need all the other args as well. This works much better:

heads=${@:1:$(($# - 1))}
tail=${@:$#}

Note that this is bash-only.

changed per @starfry. Quite right, $# is all that'
Source Link
AgileZebra
  • 583
  • 6
  • 16

Found this when looking to separate the last argument from all the previous one(s). Whilst some of the answers do get the last argument, they're not much help if you need all the other args as well. This works much better:

heads=${@:1:$((${#@}$# - 1))}
tail=${@:${#@}$#}

Found this when looking to separate the last argument from all the previous one(s). Whilst some of the answers do get the last argument, they're not much help if you need all the other args as well. This works much better:

heads=${@:1:$((${#@} - 1))}
tail=${@:${#@}}

Found this when looking to separate the last argument from all the previous one(s). Whilst some of the answers do get the last argument, they're not much help if you need all the other args as well. This works much better:

heads=${@:1:$(($# - 1))}
tail=${@:$#}
Source Link
AgileZebra
  • 583
  • 6
  • 16
Loading