需求是动态生成每天的日期,md5这个日期,然后curl到一个网址。
我第一次用shell,研究了下,初步代码如下:
#!/bin/bash
a=`date '+%Y-%m-%d'`
echo $a
code=$($a|md5sum|cut -d '' -f1)
echo $code
echo -n $a|md5sum
curl -v http://www.abc.com/report/?code=$code
问题1:md5sum赋值到变量和直接echo的值是不一致的
问题2:curl如何不打印请求的结果
Problem 1: I have never encountered a situation where the value assigned by md5sum to a variable and the value of direct echo are inconsistent
Your code cannot run the fourth line at least under bash
Question 2:
curl -s
你的网址
-o /dev/nullAdditional question 1:
In your script
This paragraph means copying the output result of date to a. Now the value of a is 2016-03-30
to the next line
actually became
2016-03-30 is not a command, it is a syntax error.
If you are lazy, you can also write like this:
PS: Echo needs to add -n, otherwise the output results will be affected by line breaks. I didn't add the previous code, and md5 became 3a2f84ded4cc91e1276040cf0f27a681. 2016-03-30 The correct md5 value should be a450f2d7030074e211755cdde0d41a57.
I need to assign the generated md5 value to code, and then reference the code elsewhere
After organizing the code, the following output md5 is still inconsistent