If you don’t know a scripting language or don’t know what a scripting language is, you are missing out PERIOD.
Read on to learn to be more productive and do things you enjoy rather than mundane tasks using scripting.
What is a scripting language? #
Well let’s ask ChatGPT:
A scripting language is a programming language designed for integrating and communicating with other programming languages. It’s often used to automate tasks, manipulate data, or control applications. Scripting languages typically have a simpler syntax than compiled languages, making them easier to write and use.
The key things we need to take away from that incredibly long explanation are:
- Programming Language
- Used to automate tasks & manipulate data
- Simple syntax for ease of writing and use
Now that we know what a scripting language is, you might be wondering…
Why should I know a scripting language? #
Simple.
If you want to skip over laborious and repetitive tasks and get to do things you enjoy, take a few minutes now and learn a scripting language. You don’t even need to know that much.
All you need to be able to do is read a script and understand what it does.
When you need to automate more complex tasks, you need to know how to change scripts yourself, but until then, your pal ChatGPT should be able to handle all the heavy lifting.
At this point, I hope I have convinced you why you need to know how to script.
What scripting language should I learn and how? #
There are several scripting languages to choose from. My pick would be Python; Bash is helpful too. But Python is way easier to pick up and remains my pick.
Some other languages you could also look into are Lua, Javascript, Ruby, and Perl. Ask ChatGPT what each of these languages is generally used for, and find the one that best matches your use case.
Now, let’s take a look at solving a problem with scripting.
Example #
Problem: As a college student doing courses in C, I often have to compile, run, check for errors, and repeat. It is tedious and annoying to type these commands out.
Let’s look at how we can use scripting to solve this.
Understanding the problem #
Each time I need to test my code, I need to execute the following commands:
gcc file.c -o file # Compile the code
./file # Run the code
When you have to do this several times for a single problem, it gets annoying to type repeatedly.
Scripting the Solution (Manually) #
This is how I decided to use my minimal bash skills to solve the problem:
function cr(){
name=$1
prog=$(echo $name | cut -d '.' -f1 )
gcc $name -o $prog
./$prog
}
If you need help understanding what’s written above, don’t fret. I’ll show you how you can get ChatGPT to do the work for you.
The function above takes a file name, removes the .c extension, produces an executable, and runs the executable. All with only one command!
cr file.c # Now it compiles and runs all with one command
Scripting the Solution (Using ChatGPT) #
If we ask ChatGPT the following:
Write me a bash function that takes a file name as input and compiles and runs the file
ChatGPT produces the following code and even reminds us to add the function to our .bashrc.
Remember to review any code that ChatGPT produces before putting it into use !!
run_c_file() {
if [ -z "$1" ]; then
echo "Usage: run_c_file <filename.c>"
return 1
fi
if [[ "$1" != *.c ]]; then
echo "Error: File must have a .c extension"
return 1
fi
gcc "$1" -o "${1%.c}.out"
if [ $? -eq 0 ]; then
echo "Compiled successfully. Running..."
./"${1%.c}.out"
else
echo "Compilation failed."
fi
}
By using ChatGPT as a crutch, we can slowly improve our scripting skills until we no longer need to rely on ChatGPT.
Make sure you don’t become entirely dependent on ChatGPT for scripting. It’s okay to get started using ChatGPT, however it will be useful to learn to script by yourself in the long run.
Conclusion #
I hope I’ve demonstrated the need to know a scripting language in 2024.
So what are you waiting for? Learn a scripting language !!!
The next time you get annoyed at having to do a particular task, remember scripting might be the answer.