Shell Script First
- Categories:
- notes
Lately, I have been loving to write shell scripts to automate my workflows and save time instead of coding with Ruby.
Shell scripts are a powerful tool that allows you to execute a series of commands in a specific order. This can be useful for automating repetitive tasks or complex processes that require multiple steps.
In some cases, shell scripts may not be the best tool for the job. For example, if you need to connect to a database or perform more complex logic, using a programming language like Ruby or Python may be more appropriate. However, for simple tasks, shell scripts can be a quick and efficient solution.
Let’s take a look at a sample shell script I recently wrote:
#!/bin/bash
while true; do
# Read the first 100 lines from ready.txt
head -n 100 ready.txt > run.txt
# Delete the first 100 lines from ready.txt
sed -i '1,100d' ready.txt
# Run my application
example-application run.txt
# Check if there is no data left in ready.txt, and exit the loop if true
if [[ ! -s ready.txt ]]; then
echo "no data left in ready.txt, exiting..."
break
fi
# Wait for 60 seconds before starting over
sleep 60
done
Using other programming language such as C#, Java, Go, Ruby or Python, I am sure it will require more lines of code.
To improve my shell scripts skills, currently I am learning about sed
and awk
.
Recent Posts
Broken Pipe Error
My note about Broken Pipe error
Shell Script First
In this blog post, I'll explain why I prioritize shell scripting as my primary solution for automating tasks, and only turn to full-fledged programming languages like Ruby and Python when necessary.
Lessons from Creating the Unsplash Image Resizer: Simplifying Image Downloads with HTML's Download Attribute
How I discovered the download attribute and used it to improve image downloads
C# - The Difference Between string[] and List
Learn the difference between string[] and List
in C# and when to use each for storing collections of strings in your code Output Redirection - Standard Input, Standard Output, Standard Error, /dev/null
Penjelasan singkat mengenai shell piping dan /dev/null