Using lynx in a shell, store dump for further grep

扶醉桌前 提交于 2019-12-05 22:44:48

Just fixed your code. And I want to answer to this

but i mess up between assignations, using quotes, backquotes and so on.

  • Please prefer $() instead of backticks, usually there is no difference, but one great advantage of $() is that you can nest it. Also in some fonts backticks could look similar to single quotes and if you paste your code to some sites it may break, so $() is more stable.
  • Always place " " around parameters. Examples: echo "$myvar" , wget "$myurl"
  • Use [[ ]] instead of [. [ is a test command located in /bin/test (and /bin/[ is usually symlinked to /bin/test), while [[ ]] is bash syntax. (However it seems like [ is a bash builtin now)
  • Do not use let for math operations, use (( )). Examples: (( a = 5 * b )) , echo $(( a / 20 ))
  • Use (( )) for math comparisons instead of [[ ]] since it allows intuitive <= < > >= operators. Example: if (( a <= b )); then ... instead of if [[ $a -le $b ]]; then ...
  • Prefer bash string manipulations instead of tr and other utilities. Some of them and A bit more. Example: use ${myvar^^} instead of echo "$myvar" | tr a-z A-Z
  • Most of the commands allow you to specify filename. For example, do not use cat filename | grep somestr , use grep somestr filename instead.

Your fixed code:

content=$(lynx -dump -nolist "$url")
var1=$(grep myre1 <<< "$content")
var2=$(grep myre2 <<< "$content")
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!