Spaces in $1 in shell scripts

First of all, here’s a pet peeve: many people write bash scripts
instead of shell scripts because they have the feeling it’s
the only shell out there, not because they need a bashism.
So please, if you can write portable scripts, do it —
and most of the time you can. It’s a known fact that ksh and
its variations is the most to-be-found shell, not bash.
But I digress.
If $1 or $[2…] has or can have spaces or other characters that
can trip up the shell, remember to use “$1” in your scripts instead of
plain $1. It will save you many headaches.


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