该脚本应该简单地通过循环向数组添加一个值,然后显示数组的所有项目。
#!/bin/bash
data_file="$1"
down=()
counter=0
cat $data_file | while read line; do \
isEven=$(( $counter % 2 ))
if [ $isEven -eq 0 ]; then
down+=("$line")
fi
(( counter ++ ))
done
echo ${down[@]}
exit
Run Code Online (Sandbox Code Playgroud)
但我看到的只是空字符串:
host@user$ sh script.sh data_file
host@user$
Run Code Online (Sandbox Code Playgroud)
将data_file
包含此:
81.11
11.63
81.11
11.63
81.11
11.63
81.11
11.63
Run Code Online (Sandbox Code Playgroud)
我的错在哪里?谢谢。
我无法访问我最近在 Ubuntu AWS EC2 实例上设置的 Web 服务器:
client:~ user$ curl yyy.yyy.yyy.yyyy
curl: (7) Failed to connect to yyy.yyy.yyy.yyyy port 80: Operation timed out
Run Code Online (Sandbox Code Playgroud)
Apache 已在 AWS 实例上启动并运行:
ubuntu@server:~$ sudo service apache2 status
* apache2 is running
Run Code Online (Sandbox Code Playgroud)
并且80端口已开放
ubuntu@server:~$ sudo netstat -plunt | grep apache2
tcp6 0 0 :::80 :::* LISTEN 2968/apache2
Run Code Online (Sandbox Code Playgroud)
到目前为止,我在设置 Web 服务器方面还没有那么丰富的经验,但据我所知,Apache 在安装后应该可以立即访问。我的情况可能出了什么问题?