Re: Standard .bashrc needs a minor fix
On Thu, May 06, 2010 at 09:30:20AM -0500, Chuck Remes wrote: > The standard .bashrc contains a line of code that precludes certain scripts > from executing. It has to do with > the logic for checking if the session is interactive. There's no such thing as a "standard .bashrc", at least not from the point of view of a bash bug mailing list. Files like .bashrc are supplied by the OS vendor, or created by the user. > e.g. > [ -z "$PS1" ] && return That's certainly *not* how I'd write that check. If the goal is to protect a block of commands from running when the shell is invoked without a terminal, then I'd prefer this: if [ -t 1 ]; then # All your terminal commands go here stty kill ^u susp ^z intr ^c ... fi But this bug report really needs to be made against your OS, not bash.
Re: How to overwrite a symbolic link?
Le 06/05/2010 15:53, Peng Yu a écrit : > Suppose that I have a symbolic link link1 pointing to file1. When I > write to link1, I don't want file1 change. I want it to remove the > link generated a new file and write to it. This is a very strange question. Symbolic links are expressly designed to fool everyone. Why are you using symbolic links if you do not want to be fooled? Please give more details about what you are trying to do.
Re: How to overwrite a symbolic link?
On Thu, May 6, 2010 at 5:36 PM, Bob Proulx wrote: > Peng Yu wrote: >> Is there a way to overload operators like '>' and '>>' in bash, just >> as overloading in C++, etc. Suppose I have already made some bash >> program using '>' and '>>' without thinking about symbolic link, but I >> begin aware of them later. I would be cumbersome to add a test >> statement and deciding whether 'rm' or not for each usage of '>' and >> '>>'. > > It sounds to me like you are trying to implement a "script space" > version of copy-on-write semantics? Perhaps you should investigate > using one of the filesystem based solutions. It would probably give > you a better result. > >> A more general question is how to change the behavior of a program >> (for example compiled from C code) to delete symbolic link and write a >> new file, without recompiling the program. > > A Comment: Symbolic links are designed to be transparent. Normal > programs are not aware of them. > > You could probably create an LD_PRELOAD library to intercept file > modification calls and then handle them in your own code. But I think > it would be difficult to do it all completely correctly and not to > introduce bugs. I advise against it. Would you please elaborate a little more on how to use LD_PRELOAD to modify the call. If the library (for example, 'open' from stdlib.h) is statically compiled in the binary, is LD_PRELOAD going to replace it with a different 'open' function? -- Regards, Peng
Re: How to overwrite a symbolic link?
On Fri, May 7, 2010 at 9:26 AM, Marc Herbert wrote: > Le 06/05/2010 15:53, Peng Yu a écrit : >> Suppose that I have a symbolic link link1 pointing to file1. When I >> write to link1, I don't want file1 change. I want it to remove the >> link generated a new file and write to it. > > This is a very strange question. Symbolic links are expressly designed > to fool everyone. Why are you using symbolic links if you do not want > to be fooled? > > Please give more details about what you are trying to do. Suppose I have N files in a directory that does some job. Lets say M (' and '>>' and the open file function call. This is why I ask the question in the OP. Let me know if you have any thought on solving this problem. -- Regards, Peng
Re: How to overwrite a symbolic link?
On 05/07/2010 09:02 AM, Peng Yu wrote: > Suppose I need to modify one primary file slightly to do something a > little bit different. But I still need to do the original job, > therefore I need to keep it the original M files. I can copy the whole > directory and then modify one file in the newly copied N files. But > I'll lose track of which file has been changed later on, which is > important to me. Consider using a version control system. Track the contents of your directory under your favorite VCS, like git, and then you can use version control commands to generate the delta for both primary and secondary files across any state that you committed. Or, for a one-shot solution, you could use a BSD union mount, where the difference between the mount overlay and the original directory shows exactly what was modified. But overloading bash's > and >> operators is not possible. -- Eric Blake ebl...@redhat.com+1-801-349-2682 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
Re: How to overwrite a symbolic link?
On Fri, May 7, 2010 at 10:16 AM, Eric Blake wrote: > On 05/07/2010 09:02 AM, Peng Yu wrote: >> Suppose I need to modify one primary file slightly to do something a >> little bit different. But I still need to do the original job, >> therefore I need to keep it the original M files. I can copy the whole >> directory and then modify one file in the newly copied N files. But >> I'll lose track of which file has been changed later on, which is >> important to me. > > Consider using a version control system. Track the contents of your > directory under your favorite VCS, like git, and then you can use > version control commands to generate the delta for both primary and > secondary files across any state that you committed. I can't use version control for 1. I need to frequently change file names. 2. Both primary and secondary files could be of hundred of MB or even GB. > Or, for a one-shot solution, you could use a BSD union mount, where the > difference between the mount overlay and the original directory shows > exactly what was modified. The problem is that if I have many directories that form a complex copying graph. It is not possible to keep track of all the possible lineages. Also, I need to avoid change multiple copies of the same file. > But overloading bash's > and >> operators is not possible. Is it because the underlying library that used in bash doesn't support the semantic of symbolic link that I propose? Or it is because of the OS? Is it possible to modify source code of bash to change the semantics of symbolic link. -- Regards, Peng
Re: How to overwrite a symbolic link?
On 05/07/2010 09:31 AM, Peng Yu wrote: > On Fri, May 7, 2010 at 10:16 AM, Eric Blake wrote: >> On 05/07/2010 09:02 AM, Peng Yu wrote: >>> Suppose I need to modify one primary file slightly to do something a >>> little bit different. But I still need to do the original job, >>> therefore I need to keep it the original M files. I can copy the whole >>> directory and then modify one file in the newly copied N files. But >>> I'll lose track of which file has been changed later on, which is >>> important to me. >> >> Consider using a version control system. Track the contents of your >> directory under your favorite VCS, like git, and then you can use >> version control commands to generate the delta for both primary and >> secondary files across any state that you committed. > > I can't use version control for > 1. I need to frequently change file names. > 2. Both primary and secondary files could be of hundred of MB or even GB. git handles both of those situations, without too much hassle. >> But overloading bash's > and >> operators is not possible. > > Is it because the underlying library that used in bash doesn't support > the semantic of symbolic link that I propose? Or it is because of the > OS? > > Is it possible to modify source code of bash to change the semantics > of symbolic link. Yes, it's possible to modify the source of bash to change how bash treats symlinks when using the > operator. But I would advise against it, as your fork of bash would no longer comply with POSIX, and would probably break a lot more than it fixes. Rather, if you insist on modifying bash, consider adding a new operator (maybe spelled '>;', similar to the noclobber override spelling of '>|'), so that your use of the new operator is explicit that you know what you are doing in your scripts (if the operand of the new operator is a symlink, break the symlink and create a file in its place instead of operating on the target of the symlink). -- Eric Blake ebl...@redhat.com+1-801-349-2682 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
Re: How to overwrite a symbolic link?
Le 07/05/2010 15:21, Peng Yu a écrit : > Would you please elaborate a little more on how to use LD_PRELOAD to > modify the call. If the library (for example, 'open' from stdlib.h) > is statically compiled in the binary, is LD_PRELOAD going to replace > it with a different 'open' function? Header files usually do not hold definitions (only declarations), so header files usually do not matter to LD_PRELOAD. LD_PRELOAD plays games with dynamic libraries, it cannot modify static linkage. But AFAIK 'open' is defined in the libc, so I would be quite surprised that its definition ends up statically linked into your binary. PS: you are not supposed to include stdlib.h to get the declaration of 'open'.
Re: Standard .bashrc needs a minor fix
On Friday 07 May 2010 08:49:26 Greg Wooledge wrote: > On Thu, May 06, 2010 at 09:30:20AM -0500, Chuck Remes wrote: > > e.g. > > [ -z "$PS1" ] && return > > That's certainly *not* how I'd write that check. If the goal is to > protect a block of commands from running when the shell is invoked > without a terminal, then I'd prefer this: > > if [ -t 1 ]; then > # All your terminal commands go here > stty kill ^u susp ^z intr ^c > ... > fi the somewhat common test ive seen in different distros to detect interactive shells is: if [[ $- != *i* ]] ; then # shell is non-interactive return fi -mike signature.asc Description: This is a digitally signed message part.