Tags: command line
cp interactive copy
2007/11/24 @ 18:50Is it just me or has the behavior of cp in linux distributions changed recently? cp is non-interactive by default so a lot of people, myself included, set an alias to include the -i flag so that cp was interactive by default.
alias cp=cp -i
But I used to enjoy the fact that if I set this alias it would prompt me when overwriting files but if there was a situation where I wanted it to be non-interactive I could do that by specifying -f. Basically, the last -i or -f would win. I want interative by default but the ability to specify non-interactive at my discretion.
However, recently or so, I noticed that several linux distributions include a cp that if you specify a cp -i alias you cannot specify -f to use non-interactive mode. The -f is ignored or at least doesn't cancel out the -i. Perhaps there is another way do to what I want but I'm unaware of it at the moment. Currently I have to remove the alias, do the non-interactive copy, and then reinstate the alias. Super annoying.
Update: You can bypass an alias by putting quotes around the command like so,
"cp" source destination
Setting output of a program to a variable in Windows Batch
2007/11/07 @ 18:03I recently had to do this to get TortoiseMerge working with Mercurial within Cygwin. It turned out to be pretty easy and I couldn't believe that a lot of people were saying that you had to route the output to a temporary file and then read it back into your program or some such garbage. Anyway, behold!!
for /f "tokens=1" %%A in (
'"cygpath -w %1"' ) do set TMergePath1=%%A
It's kind of a hack using the FOR /f but it basically allows you to set the output of a program to a variable. You can even parse the output to pull out a particular piece of the output to put in the variable. This is particularly useful with windows commandline programs which weren't really made to be piped and redirected.
Anyway, in my case I'm setting the output of cygpath called on a cygwin path to convert it into a windows path and then set the output to the TMergePath variable. The "tokens=1" part tells the program that I only want to call the code after "do" for the first token. In my case there is only one anyway. You can set "tokens=1,2,4" if you want to loop for the first, second and forth tokens. You can also set the delimiter like "tokens=1,2,4 delims=;" if your output looks like token1;token2;token3;token4









