Bash-IF语句
这是一个很难回答的问题。。我想。但是我不能让这个脚本工作。它将包含在我几天前在这里询问的一个脚本中()。基本上,我希望能够刮一个网站的一部分文字,并返回一个在线/离线的答案。我为糟糕的格式和奇怪的变量名道歉。谢谢你的关注和帮助Bash-IF语句,bash,if-statement,Bash,If Statement,这是一个很难回答的问题。。我想。但是我不能让这个脚本工作。它将包含在我几天前在这里询问的一个脚本中()。基本上,我希望能够刮一个网站的一部分文字,并返回一个在线/离线的答案。我为糟糕的格式和奇怪的变量名道歉。谢谢你的关注和帮助 #!/bin/bash printf "" > /Users/USER12/Desktop/domainQueryString_output.txt domainCurlRequest="curl https://www.google.com/?gws_rd=ssl
#!/bin/bash
printf "" > /Users/USER12/Desktop/domainQueryString_output.txt
domainCurlRequest="curl https://www.google.com/?gws_rd=ssl"
ifStatementConditional="grep 'google.com' /Users/USER12/Desktop/domainQueryString_output.txt | wc -l"
echo $($domainCurlRequest) >> /Users/USER12/Desktop/domainQueryString_output.txt
if [ $ifStatementConditional -eq 2 ] ;
then second_check="online"
else second_check="DOMAIN IS OFFLINE"
fi
echo $second_check
在尝试运行此脚本时,我一直遇到以下错误
/Users/USER12/Desktop/domain_status8working.sh: line 6: [: too many arguments
我试图用另一种方式重写,但也出现了同样的错误,所以我的逻辑、语法或其他东西都不正确
再次感谢您的关注和帮助
ifStatementConditional=“grep'google.com'/Users/USER12/Desktop/domainQueryString_output.txt | wc-l”
这是一个字符串赋值。您可能需要backticks或$()构造。否则,$ifStatementConditional将永远不等于2
if [ $ifStatementConditional -eq 2 ] ;
ifStatementConditional=“grep'google.com'/Users/USER12/Desktop/domainQueryString_output.txt | wc-l”
这是一个字符串赋值。您可能需要backticks或$()构造。否则,$ifStatementConditional将永远不等于2
if [ $ifStatementConditional -eq 2 ] ;
ifStatementConditional=“grep'google.com'/Users/USER12/Desktop/domainQueryString_output.txt | wc-l”
这是一个字符串赋值。您可能需要backticks或$()构造。否则,$ifStatementConditional将永远不等于2
if [ $ifStatementConditional -eq 2 ] ;
ifStatementConditional=“grep'google.com'/Users/USER12/Desktop/domainQueryString_output.txt | wc-l”
这是一个字符串赋值。您可能需要backticks或$()构造。否则,$ifStatementConditional将永远不等于2
if [ $ifStatementConditional -eq 2 ] ;
这扩展为:
if [ grep 'google.com' /Users/USER12/Desktop/domainQueryString_output.txt | wc -l -eq 2 ] ;
这就解释了你的错误
我想你的意思是:
#!/bin/bash
curl "https://www.google.com/?gws_rd=ssl" > /Users/USER12/Desktop/domainQueryString_output.txt
ifStatementConditional=$("grep 'google.com' /Users/USER12/Desktop/domainQueryString_output.txt | wc -l")
if [ $ifStatementConditional -eq 2 ] ; then
second_check="online"
else
second_check="DOMAIN IS OFFLINE"
fi
echo $second_check
printf”“>somefile.txt
$()
用于捕获子shell输出。这就是这里缺少的东西if [ grep 'google.com' /Users/USER12/Desktop/domainQueryString_output.txt | wc -l -eq 2 ] ;
这就解释了你的错误
我想你的意思是:
#!/bin/bash
curl "https://www.google.com/?gws_rd=ssl" > /Users/USER12/Desktop/domainQueryString_output.txt
ifStatementConditional=$("grep 'google.com' /Users/USER12/Desktop/domainQueryString_output.txt | wc -l")
if [ $ifStatementConditional -eq 2 ] ; then
second_check="online"
else
second_check="DOMAIN IS OFFLINE"
fi
echo $second_check
printf”“>somefile.txt
$()
用于捕获子shell输出。这就是这里缺少的东西if [ grep 'google.com' /Users/USER12/Desktop/domainQueryString_output.txt | wc -l -eq 2 ] ;
这就解释了你的错误
我想你的意思是:
#!/bin/bash
curl "https://www.google.com/?gws_rd=ssl" > /Users/USER12/Desktop/domainQueryString_output.txt
ifStatementConditional=$("grep 'google.com' /Users/USER12/Desktop/domainQueryString_output.txt | wc -l")
if [ $ifStatementConditional -eq 2 ] ; then
second_check="online"
else
second_check="DOMAIN IS OFFLINE"
fi
echo $second_check
printf”“>somefile.txt
$()
用于捕获子shell输出。这就是这里缺少的东西if [ grep 'google.com' /Users/USER12/Desktop/domainQueryString_output.txt | wc -l -eq 2 ] ;
这就解释了你的错误
我想你的意思是:
#!/bin/bash
curl "https://www.google.com/?gws_rd=ssl" > /Users/USER12/Desktop/domainQueryString_output.txt
ifStatementConditional=$("grep 'google.com' /Users/USER12/Desktop/domainQueryString_output.txt | wc -l")
if [ $ifStatementConditional -eq 2 ] ; then
second_check="online"
else
second_check="DOMAIN IS OFFLINE"
fi
echo $second_check
printf”“>somefile.txt
$()
用于捕获子shell输出。这就是这里缺少的东西您可能只需要使用
$()
而不是双引号来包装curl语句。您可能只需要使用$()
而不是双引号来包装curl语句。您可能只需要使用$()
而不是双引号您可能只需要用$()
而不是双引号来包装curl语句谢谢。这正是我的问题所在。谢谢@我相信你。这正是我的问题所在。谢谢@我相信你。这正是我的问题所在。谢谢@我相信你。这正是我的问题所在。谢谢@Codegnom感谢你指出了我在里面的多余的printf语句。非常感谢@NoDataFound感谢您指出我在其中的多余printf语句。非常感谢@NoDataFound感谢您指出我在其中的多余printf语句。非常感谢@NoDataFound感谢您指出我在其中的多余printf语句。非常感谢@诺达发现