Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果在X时间内未获得BASH变量超时_Bash_Pid_Subshell - Fatal编程技术网

如果在X时间内未获得BASH变量超时

如果在X时间内未获得BASH变量超时,bash,pid,subshell,Bash,Pid,Subshell,嘿,伙计们,我正试图找出一种方法来超时一个变量,如果它超过X时间试图获取内容,这是基于触摸一个服务器来验证它是否有SSL。如果服务器在X秒内没有响应,我只想将变量设置为空(或者如果可能,设置一些其他标志) 我用的是 response=$(echo ^D |openssl s_client -connect ${line}:443 2> /dev/null |openssl x509 -noout -hash |grep -E '^[[:xdigit:]]{8}') 其中,$line现在是

嘿,伙计们,我正试图找出一种方法来超时一个变量,如果它超过X时间试图获取内容,这是基于触摸一个服务器来验证它是否有SSL。如果服务器在X秒内没有响应,我只想将变量设置为空(或者如果可能,设置一些其他标志)

我用的是

response=$(echo ^D |openssl s_client -connect ${line}:443 2> /dev/null |openssl x509 -noout -hash |grep -E '^[[:xdigit:]]{8}')
其中,
$line
现在是
baidu.com

我试过这样的东西

( cmdpid=$BASHPID; 
  ( sleep 10; kill $cmdpid; echo -e "\n\t$line missed window, terminating...\n" 
  ) & exec response=$(echo ^D |openssl s_client -connect ${line}:443 2> /dev/null |openssl x509 -noout -hash |grep -E '^[[:xdigit:]]{8}')
)
但是意识到了几个问题,例如A)我在子shell中,无法取出变量,B)我试图运行
response=#hash
并返回错误等

捕获变量时运行超时的最佳方式是什么

谢谢

IFS=read-t10-d''变量
IFS=read-t10-d''变量<
IFS= read -t 10 -d '' variable  <   <(yourcommand)
IFS= read -t 10 -d '' response  <   <(echo ^D |openssl s_client -connect ${line}:443 2> /dev/null |openssl x509 -noout -hash |grep -E '^[[:xdigit:]]{8}')