2016-07-25 36 views
0

我想从我的屏幕上输入读取条目,并将其推到一个数组读取屏幕值到一个数组

echo "enter the day, example 01 or 02 etc..enter CTRL+D to break"; 

while read line; 
do 
    my_array=("${my_array[@]}" $line) 
done 

但是当我试着执行它时,我收到以下错误

第5行的语法错误:`my_array ='不是预期的。

任何输入什么是外壳检测

PS的语法错误:我已经运行在壳以及bash的上述snipet,错误仍然存​​在 OS:AIX 7.1

+0

[linux的bash脚本得到一个阵列中的用户输入,并存储(可能的重复http://stackoverflow.com/questions/17199736/linux-bash-script-get-user-input-and-store -in-a-array) – Inian

+0

很可能你从* bash shell运行脚本*,而不是*通过* bash shell。 –

回答

1

可以运行这在bash环境下如下所示;

[email protected]:/tmp:>cat testksh.sh 
#!/bin/ksh 
echo "enter the day, example 01 or 02 etc..enter CTRL+D to break"; 
while read line; 
do 
    my_array=("${my_array[@]}" $line) 
done 

[email protected]:/tmp:>./testksh.sh 
    enter the day, example 01 or 02 etc..enter CTRL+D to break 
    ./testksh.sh[3]: 0403-057 Syntax error at line 5 : `(' is not expected. 

[email protected]:/tmp:>cat testbash.sh 
#!/bin/bash 
echo "enter the day, example 01 or 02 etc..enter CTRL+D to break"; 
while read line; 
do 
    my_array=("${my_array[@]}" $line) 
done 


[email protected]:/tmp:>./testbash.sh 
enter the day, example 01 or 02 etc..enter CTRL+D to break 
01 
相关问题