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 atest
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 ofif [[ $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 ofecho "$myvar" | tr a-z A-Z
- Most of the commands allow you to specify filename. For example, do not use
cat filename | grep somestr
, usegrep somestr filename
instead.
Your fixed code:
content=$(lynx -dump -nolist "$url")
var1=$(grep myre1 <<< "$content")
var2=$(grep myre2 <<< "$content")