January 26, 2011 Re: DVM - D Version Manager | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Gibson | On 2011-01-26 19:12, Daniel Gibson wrote: > Am 26.01.2011 09:36, schrieb Jacob Carlborg: >> On 2011-01-25 23:59, Jesse Phillips wrote: >>> Jacob Carlborg Wrote: >>> >>>> Yeah, I guess you're right, didn't think there were a lot people who >>>> used other shells. Since I almost know nothing about shell scripting and >>>> even less about non-bourne shells, will it be possible to port to other >>>> shells? How much do they differ? >>>> >>>> -- >>>> /Jacob Carlborg >>> >>> To add to Lutger's message. I believe it is sh that is required by all Posix >>> systems, or at least an equivalent. Similarly I think vi is also a requirement. >>> >>> In all likelyhood you probably used a Bash specific feature, but usually >>> everyone has bash even if they use zsh... Though Ubuntu/Debian has started >>> pointing /bin/sh to dash which is complaint with posix... >> >> Ok. I'll see I can use only sh. >> > > Debian (and probably ubuntu as well) has a package called "devscripts" which > contains a handy tool called "checkbashisms". This tool tells you if your script > uses bash-specific stuff and often even suggests a more portable alternative. That sounds like something I could use. > I haven't checked DVM yet, but if you want to have stuff done one login, put it > into ~/.profile instead of ~/.bashrc - this should be executed by all POSIX > compliant shells I think. On Mac OS X I use .bash_profile, I don't know if .profile and/or .bashrc works. The bash man page (http://linux.die.net/man/1/bash) says: "When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable." And: "When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists." I'm not sure I know the difference between "an interactive login shell" and one that isn't. I'm not 100% sure in what file to put the script in. But what I want is to run a script when a new shell is started, like when you open the Terminal in Ubuntu/Mac OS X or opens a new tab in the terminal. > Cheers, > - Daniel -- /Jacob Carlborg |
January 26, 2011 Re: DVM - D Version Manager | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On 2011-01-26 14:58, Steven Schveighoffer wrote: > On Wed, 26 Jan 2011 03:36:24 -0500, Jacob Carlborg <doob@me.com> wrote: > >> On 2011-01-25 23:59, Jesse Phillips wrote: >>> Jacob Carlborg Wrote: >>> >>>> Yeah, I guess you're right, didn't think there were a lot people who >>>> used other shells. Since I almost know nothing about shell scripting >>>> and >>>> even less about non-bourne shells, will it be possible to port to other >>>> shells? How much do they differ? >>>> >>>> -- >>>> /Jacob Carlborg >>> >>> To add to Lutger's message. I believe it is sh that is required by >>> all Posix systems, or at least an equivalent. Similarly I think vi is >>> also a requirement. >>> >>> In all likelyhood you probably used a Bash specific feature, but >>> usually everyone has bash even if they use zsh... Though >>> Ubuntu/Debian has started pointing /bin/sh to dash which is complaint >>> with posix... >> >> Ok. I'll see I can use only sh. > > FWIW, /bin/sh is usually a symlink to bash, and it makes bash behave > like the original Bourne Shell. /bin/sh is not a symlink on Mac OS X. I guess I just can try to use sh instead of bash. > I typically find /bin/sh features to be enough for implementing most > scripts. I have no idea. I need to be able use the following commands/functions: export, source, builtin hash, rm, echo, exit, exec > A good reference (if you don't have it) is Unix in a nutshell, probably > my most used textbook. Ok, I'll have a look. > -Steve -- /Jacob Carlborg |
January 26, 2011 Re: DVM - D Version Manager | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jérôme M. Berger | On 2011-01-26 21:04, "Jérôme M. Berger" wrote: > Jacob Carlborg wrote: >> On 2011-01-25 23:59, Jesse Phillips wrote: >>> Jacob Carlborg Wrote: >>> >>>> Yeah, I guess you're right, didn't think there were a lot people who >>>> used other shells. Since I almost know nothing about shell scripting and >>>> even less about non-bourne shells, will it be possible to port to other >>>> shells? How much do they differ? >>>> >>>> -- >>>> /Jacob Carlborg >>> >>> To add to Lutger's message. I believe it is sh that is required by all >>> Posix systems, or at least an equivalent. Similarly I think vi is also >>> a requirement. >>> >>> In all likelyhood you probably used a Bash specific feature, but >>> usually everyone has bash even if they use zsh... Though Ubuntu/Debian >>> has started pointing /bin/sh to dash which is complaint with posix... >> >> Ok. I'll see I can use only sh. >> > You cannot. You need to modify the environment for the current > shell, which is the shell that the user is currently using (no > matter what else may or may not be installed on the system). This > has two consequences: > > - You need to have some code that is run when the shell starts (i.e. > from .bashrc, .zshrc or .kshrc). That code will define the proper > aliases and/or functions (at the time being, this is mostly the > "dvm" function in "dvm.sh" (*)). This can be accomplished by having > a different version of this file for each shell; Is it possible to detect what shell is running and then load the correct version? > - You need to generate the contents of $dvm_result_path in a format > that the shell will understand. The easiest way to do that is > probably to define a few extra functions in "dvm.sh" to enable > setting environment variables in a portable way and handle > additional requirements (like "builtin hash -r" which is definitely > a bash-ism). Then generate the $dvm_result_path using these > functions instead of the normal shell syntax. The contents of $dvm_result_path will only export one variable. > Jerome > > (*) BTW, I hope you do not add the full contents of dvm.sh nor a > "source dvm.sh" in .bashrc the way it is now. Otherwise, a > misconfiguration may prevent the user from starting a shell! OK, how else can I do the same thing? BTW this is how RVM (Ruby Version Manager) works, where I got the idea from. The whole RVM is written in shell script and it's sourced in .bashrc. -- /Jacob Carlborg |
January 26, 2011 Re: DVM - D Version Manager | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Wed, 26 Jan 2011 15:24:56 -0500, Jacob Carlborg <doob@me.com> wrote: > On 2011-01-26 14:58, Steven Schveighoffer wrote: >> On Wed, 26 Jan 2011 03:36:24 -0500, Jacob Carlborg <doob@me.com> wrote: >> >>> On 2011-01-25 23:59, Jesse Phillips wrote: >>>> Jacob Carlborg Wrote: >>>> >>>>> Yeah, I guess you're right, didn't think there were a lot people who >>>>> used other shells. Since I almost know nothing about shell scripting >>>>> and >>>>> even less about non-bourne shells, will it be possible to port to other >>>>> shells? How much do they differ? >>>>> >>>>> -- >>>>> /Jacob Carlborg >>>> >>>> To add to Lutger's message. I believe it is sh that is required by >>>> all Posix systems, or at least an equivalent. Similarly I think vi is >>>> also a requirement. >>>> >>>> In all likelyhood you probably used a Bash specific feature, but >>>> usually everyone has bash even if they use zsh... Though >>>> Ubuntu/Debian has started pointing /bin/sh to dash which is complaint >>>> with posix... >>> >>> Ok. I'll see I can use only sh. >> >> FWIW, /bin/sh is usually a symlink to bash, and it makes bash behave >> like the original Bourne Shell. > > /bin/sh is not a symlink on Mac OS X. I guess I just can try to use sh instead of bash. Yes, it should limit you to /bin/sh supported commands > >> I typically find /bin/sh features to be enough for implementing most >> scripts. > > I have no idea. I need to be able use the following commands/functions: > > export, source, builtin hash, rm, echo, exit, exec export => supported, but has a more limited syntax than bash source => supported via . builtin hash => supported rm => command (shell independent) exit => supported exec => supported -Steve |
January 26, 2011 Re: DVM - D Version Manager | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | "Jacob Carlborg" <doob@me.com> wrote in message news:ihq02n$28ki$1@digitalmars.com... > On 2011-01-26 14:58, Steven Schveighoffer wrote: >> On Wed, 26 Jan 2011 03:36:24 -0500, Jacob Carlborg <doob@me.com> wrote: >> >> I typically find /bin/sh features to be enough for implementing most scripts. > > I have no idea. I need to be able use the following commands/functions: > > export, source, builtin hash, rm, echo, exit, exec > Can't all (or most) of that be done in straight D? |
January 26, 2011 Re: DVM - D Version Manager | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | On 2011-01-26 21:53, Nick Sabalausky wrote: > "Jacob Carlborg"<doob@me.com> wrote in message > news:ihq02n$28ki$1@digitalmars.com... >> On 2011-01-26 14:58, Steven Schveighoffer wrote: >>> On Wed, 26 Jan 2011 03:36:24 -0500, Jacob Carlborg<doob@me.com> wrote: >>> >>> I typically find /bin/sh features to be enough for implementing most >>> scripts. >> >> I have no idea. I need to be able use the following commands/functions: >> >> export, source, builtin hash, rm, echo, exit, exec >> > > Can't all (or most) of that be done in straight D? It all comes done to one thing, the "source" function. If you launch an application in a shell that application can't set environment variables that will be available to the shell when the application exits. So instead I have most of the application written in D with a bash function that wraps the application. It works like this: 1. The function calls the D application 2. The D application performs all it needs to and writes a shell script to a file 3. The bash function calls "source" with this file as a parameter -- /Jacob Carlborg |
January 26, 2011 Re: DVM - D Version Manager | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On 2011-01-26 21:47, Steven Schveighoffer wrote: > On Wed, 26 Jan 2011 15:24:56 -0500, Jacob Carlborg <doob@me.com> wrote: > >> On 2011-01-26 14:58, Steven Schveighoffer wrote: >>> On Wed, 26 Jan 2011 03:36:24 -0500, Jacob Carlborg <doob@me.com> wrote: >>> >>>> On 2011-01-25 23:59, Jesse Phillips wrote: >>>>> Jacob Carlborg Wrote: >>>>> >>>>>> Yeah, I guess you're right, didn't think there were a lot people who >>>>>> used other shells. Since I almost know nothing about shell scripting >>>>>> and >>>>>> even less about non-bourne shells, will it be possible to port to >>>>>> other >>>>>> shells? How much do they differ? >>>>>> >>>>>> -- >>>>>> /Jacob Carlborg >>>>> >>>>> To add to Lutger's message. I believe it is sh that is required by >>>>> all Posix systems, or at least an equivalent. Similarly I think vi is >>>>> also a requirement. >>>>> >>>>> In all likelyhood you probably used a Bash specific feature, but >>>>> usually everyone has bash even if they use zsh... Though >>>>> Ubuntu/Debian has started pointing /bin/sh to dash which is complaint >>>>> with posix... >>>> >>>> Ok. I'll see I can use only sh. >>> >>> FWIW, /bin/sh is usually a symlink to bash, and it makes bash behave >>> like the original Bourne Shell. >> >> /bin/sh is not a symlink on Mac OS X. I guess I just can try to use sh >> instead of bash. > > Yes, it should limit you to /bin/sh supported commands > >> >>> I typically find /bin/sh features to be enough for implementing most >>> scripts. >> >> I have no idea. I need to be able use the following commands/functions: >> >> export, source, builtin hash, rm, echo, exit, exec > > export => supported, but has a more limited syntax than bash > source => supported via . > builtin hash => supported > rm => command (shell independent) > exit => supported > exec => supported > > -Steve Ok, thanks. -- /Jacob Carlborg |
January 26, 2011 Re: DVM - D Version Manager | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 2011-01-26 15:24:56 -0500, Jacob Carlborg <doob@me.com> said: > /bin/sh is not a symlink on Mac OS X. I guess I just can try to use sh instead of bash. But should it output this? $ /bin/sh --version GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0) Copyright (C) 2007 Free Software Foundation, Inc. $ This is on Mac OS X 10.6.6. -- Michel Fortin michel.fortin@michelf.com http://michelf.com/ |
January 27, 2011 Re: DVM - D Version Manager | ||||
---|---|---|---|---|
| ||||
Posted in reply to Michel Fortin | On 2011-01-26 23:46, Michel Fortin wrote: > On 2011-01-26 15:24:56 -0500, Jacob Carlborg <doob@me.com> said: > >> /bin/sh is not a symlink on Mac OS X. I guess I just can try to use sh >> instead of bash. > > But should it output this? > > $ /bin/sh --version > GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0) > Copyright (C) 2007 Free Software Foundation, Inc. > $ > > This is on Mac OS X 10.6.6. I have no idea. Perhaps it will run bash in a mode which is compatible with sh. -- /Jacob Carlborg |
January 27, 2011 Re: DVM - D Version Manager | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | Am 27.01.2011 13:05, schrieb Jacob Carlborg:
> On 2011-01-26 23:46, Michel Fortin wrote:
>> On 2011-01-26 15:24:56 -0500, Jacob Carlborg <doob@me.com> said:
>>
>>> /bin/sh is not a symlink on Mac OS X. I guess I just can try to use sh
>>> instead of bash.
>>
>> But should it output this?
>>
>> $ /bin/sh --version
>> GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)
>> Copyright (C) 2007 Free Software Foundation, Inc.
>> $
>>
>> This is on Mac OS X 10.6.6.
>
> I have no idea. Perhaps it will run bash in a mode which is compatible
> with sh.
>
Or just in normal mode, like linux distributions have been done for ages (and some still do).
bash *is* compatible with sh (=> everything that runs in sh runs in bash), but sh is not compatible with bash (=> bash has features that other sh-compliant shells don't have and that are not required by the corresponding POSIX standard).
|
Copyright © 1999-2021 by the D Language Foundation