[EMAIL PROTECTED] wrote: > I would like to report what I think is a bug: why the following linux > "date" command fails to run within a shell script. But, in runs fine on > the command line. I'm running 2.6.21-1.3194.fc7 on a IBM Thinkpad. I've > also tested on an IBM eServer running 2.6.9-55.ELsmp with the same > results. From the shell, it fails with an "extra operand" error. It seems > to misinterpreting the date string and/or formatting string.
It's good that you let us know what kernel versions you're running, but that's sort of irrelevant. It would have been better to tell us what version of coreutils you're using, but in this case the problem isn't related to coreutils either. > TDATE="2007-06-01 01:01:01" > echo $TDATE > # > echo "Test#1" > date +%s -d $TDATE > #OR > echo "Test#2" > date -d $TDATE +'%s' > #OR > echo "Test#3" > EDATE=`date -d $TDATE +'%s'` > echo $EDATE > #OR > echo "Test#4" > EDATE=`date +'%s' -d $TDATE` > echo $EDATE This is not a date bug; it's not a shell bug either, it's a misunderstanding of how shell quoting works. The thing after -d must be specified to 'date' as a single argument. When you enter the command at the prompt, you accomplish this by surrounding it in quotes. However, in your script, the quoting is absent and so you end up passing each word of the date string as a separate argument, which is invalid input to date, which complains. Everywhere that you have $TDATE you need to use "$TDATE". Note that just using quotes when you assign to TDATE is not sufficient, because the shell re-parses the command when you invoke date and unless you use quotes there, it will not know that the multiple words contained in the variable should be kept together as one argument. Brian _______________________________________________ Bug-coreutils mailing list [email protected] http://lists.gnu.org/mailman/listinfo/bug-coreutils
