echo -n "# WHICH DAYS? #"
read day
assume user's неудар в лунку пахал: 100
101
with one space between numbers. For example I need to extract first and second column оцените of day separately, which command gives this оцените? I tried below commands but they give whole array;
first_column_of_day=${day[${1}]}
echo "$first_column_of_day"
second_column_of_day=${day[${2}]}
echo "$second_column_of_day"
Во-первых, необходимо сказать read
использовать массив. От help read
:
-a array assign the words read to sequential indices of the array
variable ARRAY, starting at zero
Так, сделайте:
read -a day
Затем используйте просто 1
и 2
, без ${...}
. В этом случае, как текст справки отмечает, запустите с 0
:
first_column_of_day="${day[0]}"
second_column_of_day="${day[1]}"
${1}
первый аргумент сценарию, который может или не может быть 1
.
Также отметьте это bash
read
может распечатать подсказку:
-p prompt output the string PROMPT without a trailing newline before
attempting to read
Так:
read -p "# WHICH DAYS? #" -a day