From 0e3397b2252b52edca3743469db6bd5db8154cfd Mon Sep 17 00:00:00 2001 From: Jim Tang Date: Wed, 3 Oct 2018 18:25:50 +0800 Subject: [PATCH] Envsetup: Fix lunch choice with number in zsh (zsh)$ source build/envsetup.sh; lunch 23 will result in selecting #22 because array in zsh starts from 1 instead of 0. This CL is to fix this issue. Bug: b/117202855 Test: below commands should have the same output: (zsh)$ source build/envsetup.sh; lunch 23 (zsh)$ source build/envsetup.sh; lunch aosp_walleye-userdebug Change-Id: I0570585417878bc7c73eda0e1a416232fe147fb4 --- envsetup.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/envsetup.sh b/envsetup.sh index 58941440b2..5cbd9ebdbc 100644 --- a/envsetup.sh +++ b/envsetup.sh @@ -585,7 +585,13 @@ function lunch() local choices=($(TARGET_BUILD_APPS= LUNCH_MENU_CHOICES="${LUNCH_MENU_CHOICES[@]}" get_build_var COMMON_LUNCH_CHOICES)) if [ $answer -le ${#choices[@]} ] then - selection=${choices[$(($answer-1))]} + # array in zsh starts from 1 instead of 0. + if [ -n "$ZSH_VERSION" ] + then + selection=${choices[$(($answer))]} + else + selection=${choices[$(($answer-1))]} + fi fi else selection=$answer