You are not logged in.

#1 2014-05-20 09:21:32

Rexilion
Member
Registered: 2013-12-23
Posts: 784

[solved!] Construct program arguments based on file contents

I tried to look on Stackoverflow and Google in general. Maybe I'm using the wrong keywords so I'm posting it here. Sorry if this has been answered already (which I think it is, but cannot find it).

I'm currently migrating from rsync to unison. Rsync has an option to designate a file containing a path on each line to ignore. Unison does not have that. So, I'm trying to create something like this:


 < construct arguments and put them in IGNORE >

unison / /backup -path usr -path etc -path var -path boot -path opt -path home -path usr/src/linux-git $IGNORE

However, I cannot get '< construct arguments and put them in IGNORE >' right. It seems that bash puts excessive amounts of quotation marks around my arguments so unison does not like it. I tried for example, something like this: (/home/gebruiker/Documenten/backup_wel contains one entry)

< construct arguments and put them in IGNORE >:

while IFS=$'\n' read -a path; do
    IGNORE+="-ignorenot \'BelowPath ""$path"\"\ 
done < /home/gebruiker/Documenten/backup_wel

Causes:

+ unison / /backup -path usr -path etc -path var -path boot -path opt -path home -path usr/src/linux-git -ignorenot '\'\''BelowPath' '/usr/src/linux-git/.git/"'
Uncaught exception Sys_error("Is a directory")

< construct arguments and put them in IGNORE >:

while IFS=$'\n' read -a path; do
    IGNORE+="-ignorenot \"BelowPath $path\" "
done < /home/gebruiker/Documenten/backup_wel

Causes:

+ unison / /backup -path usr -path etc -path var -path boot -path opt -path home -path usr/src/linux-git -ignorenot '"BelowPath' '/usr/src/linux-git/.git/"'
Uncaught exception Sys_error("Is a directory")

< construct arguments and put them in IGNORE >:

export IFS=$'\n'

for path in $(cat /home/gebruiker/Documenten/backup_wel)
	do IGNORE+="-ignorenot \"BelowPath $path\" "
done

unset IFS

Causes:

+ unison / /backup -path usr -path etc -path var -path boot -path opt -path home -path usr/src/linux-git -ignorenot '"BelowPath' '/usr/src/linux-git/.git/"'
Uncaught exception Sys_error("Is a directory")

I just want each line in my exception file to be completely taken out, manually prefixed by the script and then used as a commandline argument in the final command. I'm starting  to think I'm missing something very trivial. I stumbled on this before, but this time I would like to know. Could anyone help?

Last edited by Rexilion (2014-05-20 10:22:08)


fs/super.c : "Self-destruct in 5 seconds.  Have a nice day...\n",

Offline

#2 2014-05-20 10:21:37

Rexilion
Member
Registered: 2013-12-23
Posts: 784

Re: [solved!] Construct program arguments based on file contents

heh.

< construct arguments and put them in IGNORE >:

export IFS=$'\n'

for path in $(cat /home/gebruiker/Documenten/backup_wel)
	do IGNORE+=(-ignorenot)
	IGNORE+=("BelowPath $path")
done

unset IFS

causes:

unison / /backup -path usr -path etc -path var -path boot -path opt -path home -path usr/src/linux-git -ignorenot 'BelowPath usr/src/linux-git/.git/'

This is *exactly* what I wanted. But, that is not quite right yet (whitespace springs to mind):

< construct arguments and put them in IGNORE >:

export IFS=$'\n'

for path in $(cat /home/gebruiker/Documenten/backup_wel)
	do IGNORE+=(-ignorenot)
	IGNORE+=("BelowPath \"$path\"")
done

unset IFS

causes:

+ unison / /backup -path usr -path etc -path var -path boot -path opt -path home -path usr/src/linux-git -ignorenot 'BelowPath "usr/src/linux-git/.g it/"'

I still have no idea why this works, but this is a nice starting point for further examination and deepening.

EDIT: Turns out I have to use the first variant. The second variant includes the double quotation character which cannot be right. If I exclude those, unison starting to complain about leading slashes, which is good. I guess the first quotation marks handle any whitespaces inside the path.

Last edited by Rexilion (2014-05-20 10:56:36)


fs/super.c : "Self-destruct in 5 seconds.  Have a nice day...\n",

Offline

Board footer

Powered by FluxBB