Skip navigation

Shell scripting!

I’ve been coding off and on in a number of different languages (around seven by my count) since I got my first graphing calculator back in 1999, but I’d never written a shell script before today. I mean, yes, I’d copied other people’s shell scripts from the internet when it’s suited me, but I’d never written my own before.

That all changed today when I was reading an article in Scientific American on the subject of internet comment threads. In the article, the author mentions the concept of disemvoweling trolls, which struck me as a good thing to automate. Thus, my first shell script was born.

I’ll give you the code in a moment, but before I do, in debugging the program (who would have thought that you needed to debug two lines of code?), I learned something useful: when writing shell scripts, your variable names should not have trailing whitespace before the = or they will not be seen as variables (something that will take some adjusting to for me, since aesthetically I prefer to have whitespace surrounding my equals signs). Maybe I should have twigged that something was off when Vim didn’t turn my variable a different color when I initialized it, but I’m new to this, so give me a break.

And now, the script (well commented and maybe not as elegant as it could be, but, again, it’s my first time, so give me a break):


# This script will disemvowel its input and feed it into a new file

# Create a disemvoweled version of the file being read

# Disemvowel file with sed and feed into new file
sed -e 's/[AEIOUaeiou]//g' $1 >> "$DSMVLD"

Of course, I could easily make it so this could to batch disemvowelment, butI can always do that later if I actually see the need to disemvowel more than a few files at a time.

If you want and if you can, feel free to share your first scripts, or any fun scripts you’ve written in the comments.


One Comment

  1. bash is by far the fussiest thing i’ve coded with in terms of whitespace…well ok, COBOL was worse. God I hate COBOL

    Here’s something I find handy

    while ps -p $1 > /dev/null
    sleep 1

    Because usually I’ll fork something on my local machine, close the terminal, decide that I want to shutdown but can’t because I still have that process (and I don’t want to guess when to schedule the shutdown). Well wait isn’t going to work anymore if I closed the terminal so said loop is pretty handy

    # /path/to/ ; echo “now do whatever you want. for example”;shutdown -h now

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: