On Mon, May 15, 2017 at 04:10:17PM +0000, Alistair Grant wrote: > On Mon, May 15, 2017 at 08:14:44AM -0700, Eliot Miranda wrote: > > > > > > On Mon, May 15, 2017 at 8:09 AM, Damien Pollet <[email protected]> > > wrote: > > > > My point was, if #shellCommand: accepts a single string for a whole > > command, then surely it passes it to a system shell already, so why > > nest a > > bash in between? (effectively running the equivalent of sh -c "bash -c > > \"ls > > ~\"') > > > > > > Clearly it doesn't do that otherwise Denis wouldn't have found that tile was > > unexpanded. I agree with you that it should. shellCommand: feels like a > > misnomer otherwise. > > I'm not sure why Denis is having problems, but... > > OSSUnixSubprocess>>shellCommand: aShellCommandString > "This is a simple facility method for the cases when the user wants to > use shell as the program. > This way, the user can directly send > shellCommand: 'ls -la | grep Pharo > /tmp/test.txt ' with the whole > string > rather than having to do set the command sh, send the '-c' argument, > etc etc etc. > We first try to use the SHELL defined in the OS by getting the env > variable $SHELL. > If not found, then we fallback to /bin/sh" > command := Smalltalk platform environment at: 'SHELL' ifAbsent: > ['/bin/sh']. > arguments := Array with: '-c' with: aShellCommandString. > > > And if I execute the following in a playground: > > | ls | > OSSUnixSubprocess new > shellCommand: 'ls ~'; > redirectStdout; > runAndWaitOnExitDo: [ :process :outString | > ls := outString > ]. > ls. > > > It returns the expected value.
One thought: Denis, are you using a non-English keyboard? Is there any chance that what you are entering looks like a tilda, but is some other unicode character? Maybe copy-and-paste the code I entered above? Cheers, Alistair > > On 15 May 2017 at 16:28, Eliot Miranda <[email protected]> wrote: > > > > Hi Damien, > > > > On May 15, 2017, at 6:44 AM, Damien Pollet <[email protected]> > > wrote: > > > > > > On 15 May 2017 at 15:26, Eliot Miranda <[email protected]> > > wrote: > > > > Try something like > > > > shellCommand: 'bash -c ''ls ~'''; > > > > > > But then that would run ls inside of bash inside of the system > > shell (/bin/sh), wouldn't it? What's the point? > > > > > > -c's argument is parsed by the shell so one gets full expansion. > > Further, if there are arguments after the string, they are assigned > > to > > the positional parameters, so that > > > > sh -c 'echo ~/$0' foo > > > > prints /Users/eliot/foo > > > > That may be useful.
