Bash is a shell and a command language. You can use it like any other language to write scripts. Bash scripts can run on Linux and Mac right off. F...
For further actions, you may consider blocking this person and/or reporting abuse
This is a great article! Once you get the basics down, ShellCheck is a great tool to use to make these and other syntax and style "rules" easier to remember (or not have to remember at all!). shellcheck.net
It can be easily added as a linter to Vim, Emacs, VS Code, and others.
This sounds like something I definitely need! Thanks!
Thank you for your tutorial!
Thereβs one thing I see missing: If you use bash, you can do quick string operations in variables:
A=abc123foo.txt
strip suffix:
echo ${A%.txt} # abc123foo
strip suffix with globbing:
echo ${A%foo*} # abc123
strip prefix:
echo ${A#abc} # 123foo.txt
strip prefix with globbing:
echo ${A#*c} # 123foo.txt
Thanks, that's really useful!
This is an excellent article. I've been working (less than I'd like to admit) on learning Bash. I've observed that floating point arithmetic is amazingly difficult (Or i've missed something obvious) and dealing with dates that are not GNU formatted typically yields my writing embarrassing and nonsensical pipes into sed / awk.
Any pointers for doing floating point math and handling dates for newbs like me?
Appreciate your sharing.
Let me tell you a secret. Before writing this article I didn't know Bash myself. I've realized that teaching is the best way to learn. Maybe you can write a part two to this article explaining dates and floating-pointing arithmetic. I'm pretty sure you'll learn a lot from the process! Hope this helps π
Hello @dsbarnes ,
You can not do floating point arithmetic natively in Bash, but there is a trick I use i.e. using the 'bc' command like:
echo "3.142 + 3.142" | bc -l # add the value of pi to itself
echo "sqrt(49)" | bc -l # find the square root of 49
echo "scale=2; sqrt(91)" | bc -l # To find the square root of 91 to just 2 decimal places.
The capabilities of bc is extremely wide. Check the Manpage for its full documentation.
This is a great article!
If you are a fan of opensource, feel free to contribute to the Introduction to Bash Scripting open-source eBook on GitHub!
on the begining of the tutorial, i had to use
chmod +x ./script.sh
instead ofchmod -x ./script.sh
to make it executable, am I missing something?Yup, yours is correct. I added the
-
out of habit! Fixed. Thanks πThanks for this fun handzone π
**small typo in section 6
[[ -n "$str" ]] # True if string is not of length zero
fixed!
Thanks great article.
I'm glad! And thank-you for reading!
ππ½ππ½ππ½
This is really useful, you saved me a lot of time. Also, great posts ππ»ππ».
Thanks man!
A well written and concise crash course! This is a great diving board into other shell scripting topics like simple automation.
Thanks π