Some comments on your script, starting with a few unnecessary patterns:
IFS=$(echo -en "\n\b")
1) You shouldn't generally need to save or restore IFS inside a script, unless you need to use the default value again in it. All environment settings inside the script only affect the script itself, and will be discarded on exit.
2) Bash has a special $''
quoting style (usually called ansi-c style quotes, see the QUOTING section of the man page) for inserting non-printing characters. You can use this instead of echo -e
But why would you need to set IFS to backspace
3) You don't need to echo a parameter expansion. Just set the new variable directly:
is a very old, outdated, and deprecated syntax. Do not use it. The modern version is $((..))
. But there are also ways to do arithmetic operations without expansion, in particular the let
keyword and bash's ((..))
arithmetic brackets. You can also increment a variable directly with var++
when in an arithmetic context.
5) Always remember to quote your variable expansions! Remember the links I gave you in your last thread?
6) You probably want to use a single if..elif...else
statement, rather than a series of separate if
7) Also consider using bash's new [[..]]
test instead of [..]
. It's safer and more powerful. You could combine all your tests into one command, for one thing.
if [[ -n "$s" && -z "$t" && -z "$v" ]]; then
elif [[ -z "$s" && -n "$t" && -z "$v" ]]; then
By the way, assuming I understand it correctly, I believe you can replace the whole thing with this:
doesn't exist, then it uses t
, if t
doesn't exist, it uses s
Finally, I just posted a comment in that thread with some scripting suggestions. You may want to take a look at it.