Some often used bash scripts techniques. Also an example script I wrote for my network homework which does some auto download testing.
1 | ### to start a script: |
Suppose we name out script as myscript.sh
, to run it, fisrt we givie it permission:
1 | $ chmod 755 myscript.sh |
Some some techniques (more will be added):1
2
3
4
5
6
7
8
9### string quotes
NAME="John"
echo "Hi $NAME" #=> Hi John
echo 'Hi $NAME' #=> Hi $NAME
### Conditional execution:
git commit; git push
git commit && git push
git commit || echo "Commit failed"
Now an example:
1 | # !/bin/bash |
At the end, a very good reference link: https://devhints.io/bash