How do I tell rsync to run only if the destination directory exists?
Solution 1
These two flags look like what you're looking for:
--existing, --ignore-non-existing
From the man page:
--existing, --ignore-non-existing
This tells rsync to skip creating files (including directories) that do not exist yet on the destination. If this option is combined with the --ignore-existing option, no files will be updated (which can be useful if all you want to do is delete extraneous files).
Solution 2
AFAIK no, but you can simulate the behavour with a trailing slash:
rsync -av dir_to_backup /Volumes/External/;
It will exit with an error if the directory does not exist (which may or may not be desired).
Also, you can always optimize away the if:
test -e $DIR && rsync -av ...
Solution 3
No, there does not seem to be any such option, as far as I can see from the manpage.
Gordana Jekic
Updated on June 14, 2022Comments
-
Gordana Jekic almost 2 years
I'm trying to pass string value as a function parameter, but I need string value inside function
Here is the code:
EDIT:
var array = [{someValue: 5}, {someOtherValue: 10}]; var newArray = []; var obj = {value: "someValue"}; var setValue = function(choosenValue) { for (let i = 0; i < array.length; i++) { newArray.push({ choosenValue: array[i].choosenValue }); } } setValue(obj.value);
EDIT: What I want to get is newArray=[someValue : 5]; I want to create new array from array with key that is passed as parameter and chhosenValue is also value inside array, and I want it's value. It should be array of objects with same keys but different values.
Value from object will change and depends what is chosen I need to loop through array. Since choosenValue is string I can loop properly through array.
I tried with choosenValue.valueOf(), but it doesn't work. Any other idea?
I'm getting inside push() that choosenValue is undefined.
-
Geeky over 7 yearswhat is array in the code?are you missing anything here
-
SLaks over 7 yearsWhat do you think
array[i].choosenValue
means? If you want to use your parameter, just use your parameter. -
Dan O over 7 yearsplease provide more of your code. where is
array
defined? -
rogeriolino over 7 yearsPass choosenValue as object index:
array[i][choosenValue]
-
Eduardo M - bbaaxx over 7 years
array[i].chosenvalue
is not defined nor can be defined because what you have inarray[i]
is not yet an object, it isundefined
. You cannot assign properties (choosenValue
) to undefined. -
Redu over 7 yearsIf you had already defined
newArray
andarray
somewhere in the code what is the problem? -
Gordana Jekic over 7 yearsTake a look at my edits.
-
Moob over 7 yearsIt would be a lot easier to understand what you want if you gave an example of the expected output. Most of the time spent helping you has gone on simply trying to understand your requirements. Voting to close.
-
-
Eduardo M - bbaaxx over 7 yearsAlso you have to initialize an object in
array[i]
such asif (!array[i]) {array[i] = {};)
-
Gordana Jekic over 7 yearsWhere should I do this? Before push()?
-
Gordana Jekic over 7 yearsI'm getting empty array. :(
-
Andrea Limoli over 7 yearsSee my full example in the answer and tell me what don't you uderstand.
-
Gordana Jekic over 7 yearsI understand, but this is not what I need. You are returning object, and I'm getting only one object, and I need array of objects. I have a lot of them.
-
Andrea Limoli over 7 yearsI don't understand. Give me the final result (object or array) of what do you want to retrieve.
-
Gordana Jekic over 7 yearsI want to return array. And with your example it returns new object with value of last member of array. I'm getting only one object and I need to create new array. Result should be array.
-
Andrea Limoli over 7 yearsThe last example returns an array.
-
Gordana Jekic over 7 yearsReturns empty array. :(
-
Moob over 7 years@Gordana it would be a lot easier to understand what you want if you gave an example of the expected output. Most of the time these volunteers have spent helping you has gone on simply trying to understand your requirements.
-
Moob over 7 yearsI think you're on the right lines but until the OP clarifies the requirements it just guesswork. Good answer though.
-
Gordana Jekic over 7 yearsthank you for detailed explanation. This newArray.push({ choosenValue: array[i][choosenValue] }); works only my key has name exactly "choosenValue" not value that I got from obj "someValue". How to fix that?
-
Andrea Limoli over 7 yearsPlease, answer if the provided solution is correct.
-
Andrea Limoli over 7 years@GordanaJekic have you tries the last example or not?!
-
Gordana Jekic over 7 yearsYour edit works. :) Only now I have problem to push more keys with values in array. For example I want to push id with value array[i].id in new array?
-
Gordana Jekic over 7 yearsI found a way. Thank you.