1748182 Members
3451 Online
108759 Solutions
New Discussion юеВ

Scripting help

 
SOLVED
Go to solution
Carlo Henrico_1
Regular Advisor

Scripting help

Firstly where can I get some guidelines for scripting?

Secondly, I need to test in one of my scripts whether one of the parameters entered ends with a ".h". Any ideas on how I go about this please?

Thanks

Carlo
Live fast, die young - enjoy a good looking corpse!
5 REPLIES 5
Ralph Grothe
Honored Contributor
Solution

Re: Scripting help

If you are already familiar with the basics of scripting a good reference as always are the manpages of the various shells:

man sh
man sh-posix
man ksh
man csh

Otherwise get a text book for your preferred shell.
I always found the O'Reilly books quite worthwhile.

Here is a suggestion for testing for header filename suffixes passed as parameters to a script (though this is not particularly elegant and could be done better)

#!/bin/sh

for param in $*; do
if [ "${param#*.}" = "h" ]; then
# do something
fi
done
Madness, thy name is system administration
Pedro Sousa
Honored Contributor

Re: Scripting help

Hi Carlo!
echo |grep .h > /dev/null
if [ $? != 0 ]; then
or
if [ $? = 0 ]; then

example:
echo $2 |grep .h > /dev/null

good luck.
James R. Ferguson
Acclaimed Contributor

Re: Scripting help

Carlo Henrico_1
Regular Advisor

Re: Scripting help

Pedro

Thanks so far, this seems to work however, I presume $? is the return code from the last command?

Thanks
Live fast, die young - enjoy a good looking corpse!
Pedro Sousa
Honored Contributor

Re: Scripting help

That's true...! Just to check if it went OK.
If the result is 0, then the argument has .h, if it's not then it hasn't.