Operating System - Linux
1745821 Members
3989 Online
108722 Solutions
New Discussion юеВ

Re: Something wrong with echo?

 
SOLVED
Go to solution
Marvin Strong
Honored Contributor

Re: Something wrong with echo?

You could always install pdksh on your linux box and then you have ksh, which you could then run your script asis on both hp and linux.

of course I'm sure there are people that will disagree with this solution.
Steve Start
Advisor

Re: Something wrong with echo?

Hi guys:

I really don't know Perl and I don't want to convert all of my scripts to Perl right now. Patrick's idea works and Clay's idea of using the zsh worked. I didn't even know there was a z shell. Clay, the temp file worked but shouldn't there be a rm after the file is read?

Thanks,
Steve
A. Clay Stephenson
Acclaimed Contributor

Re: Something wrong with echo?

You could certainly put an explicit rm command after the read but it isn't necessary. Note this line:
trap 'eval rm -f ${T1}' 0 1 2 15

This means that if the process receives a SIGHUP (1), a SIGINT (2), or a SIGTERM (15) that the rm command will be executed BUT note the '0' -- that is triggered on a normal exit so that when the process exits (even without a signal) the trap is still executed and the rm is done. I do see that it would also be wise to add a '3' (SIGQUIT) to the list of signals in the trap.
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: Something wrong with echo?

Hi (again) Steve:

I didn't mean to necessarily suggest that a total conversion to Perl was necessary. I meant to point out that it is a portable solution that bears consideration.

Clay's approach automatically removes the temporary file he creates when your script exits. Look at the 'trap' statement.

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Something wrong with echo?

Hi Steve:

I should add that your *shell* script could always call a perl snippet to do the work needed, no differently then shell scripts call 'awk' or 'sed programs. For instance:

TIMES=`perl -MPOSIX=strftime -le 'print strftime "Year: %Y Month: %m Day: %d Hour: %H Min: %M Sec: %S",localtime(time)'`

echo ${TIMES}

Regards!

...JRF...
Steve Start
Advisor

Re: Something wrong with echo?

Hi guys:

Thanks to everybody for all the quick answers. I will probably use zsh for now on linux and posix shell on HPUX but I may convert everything to the temp file method.

Thanks,
Steve
Eric Raeburn
Trusted Contributor

Re: Something wrong with echo?

Don't know if anyone's still following this thread, but this works on both Linux/bash and HPUX/ksh:

typeset -i i=0

t=$(date "+%Y %m %d %H %M %S")
for x in $t ; do
ts[i]=$x
i=i+1
done

echo year=${ts[0]}
echo month=${ts[1]}
echo day=${ts[2]}
echo hr=${ts[3]}
echo min=${ts[4]}
echo sec=${ts[5]}


-Eric