Quantcast
Channel: openSUSE Forums
Viewing all articles
Browse latest Browse all 40713

Script - issue with SED command

$
0
0
Hi folks,

I'm attaching an excerpt from a script I'm working at:

HTML-Code:

for i in {1..$line_nr_log}; do
    tb=$(sed "$i"'q;d '"$log"); #line i of file log.txt (cotnaining the file/dir to be backed up) is read into variable $tb
    cp -v --parents $tb $backupdir >> $temp_operations_log; #file $tb is copied to the backup directory. $tb contains the path of the file relative to /home. All directories contained in the relative path are copied in the backup directory in order to preserve the original path; output of the command obtained in verbose mode is redirected to the temp_operations_log file
done

I'm getting following errors when running bash -xv for this script:

HTML-Code:

for i in {1..$line_nr_log}; do
    tb=$(sed "$i"'q;d '"$log"); #line i of file log.txt (cotnaining the file/dir to be backed up) is read into variable $tb
    cp -v --parents $tb $backupdir >> $temp_operations_log; #file $tb is copied to the backup directory. $tb contains the path of the file relative to /home. All directories contained in the relative path are copied in the backup directory in order to preserve the original path; output of the command obtained in verbose mode is redirected to the temp_operations_log file
done
+ for i in '{1..$line_nr_log}'
sed "$i"'q;d '"$log")
sed "$i"'q;d '"$log"
++ sed '{1..2609}q;d /var/run/media/BACKUP/BACKUP/fbackup_03.05.2014/log'
sed: -e expression #1, char 3: unknown command: `.'
+ tb=
+ cp -v --parents
cp: missing file operand
Try 'cp --help' for more information.

I guess there is something wrong about the syntax of the SED command, however I can't figure out which the issue is.

I'm getting the same errors when replacing the $(sed ...) with `sed ...`.

On the other hand when using sed without variables and only with single quotes I'm not getting any errors. Here's an example:

HTML-Code:

central_backup_dir=`sed '1q;d' /home/test/bin/Backup_Scripts_Parameters`; #reading the path of the central backup directory, which is contained by the first line of the Backup_Scripts_Parameters file (this file contains certain parameters of the scripts fbackup.sh and dbackup.sh)
Thanks in advance for your help!

Cheers,
Liviu

Viewing all articles
Browse latest Browse all 40713

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>