Marcus Claesson wrote: > > Hi! Hello,
> I have a problem with variables when using command-line perl in a bash > script. The script should update a date (in 2003-10-10 form) if the > argument, which is a file name, exists on the same line in the file > updated_files.txt. > > #!/bin/bash > FILENAME=$1 > UPDATED=`date +%F` > echo > echo "perl -wne 'if (/$FILENAME/) { s/\d{4}-\d{2}-\d{2}/$UPDATED/;print; > } ' updated_files.txt" #Exactly as below, to see how the command looks > like > > perl -wne 'if (/$FILENAME/) { s/\d{4}-\d{2}-\d{2}/$UPDATED/;print; } ' > updated_files.txt > > exit Your "problem" is that the perl script is in single quotes so the shell variables are not interpolated by the shell but by perl. You could do it in the shell like this: #!/bin/bash FILENAME=$1 UPDATED=`date +%F` echo echo "perl -wne 'if (/$FILENAME/) { s/\d{4}-\d{2}-\d{2}/$UPDATED/;print; } ' updated_files.txt" #Exactly as below, to see how the command looks like perl -wne 'if (/'$FILENAME'/) { s/\d{4}-\d{2}-\d{2}/'$UPDATED'/;print; }' updated_files.txt exit However, since you are running perl anyway, you can do it in perl instead: #!/usr/bin/perl -wn BEGIN { use POSIX 'strftime'; my $filename = shift; my $updated = strftime '%F', localtime; @ARGV = 'updated_files.txt'; } if ( /$filename/ ) { s/\d{4}-\d\d-\d\d/$updated/; print; } __END__ John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]