The form I am able to use both, RunProcess[$SystemShell, prop, input]RunProcess and StartProcess, to execute a built-in shell command. At least it works for me on OSX, with zsh or sh shell.
See thisHere is a minimal example: with the built-in command source (like in the OP's question).
Let's create this file in your home directory and name it for example "myalias"First, let's choose our shell :
#!myshell = "/bin/bashzsh"; (* or "/bin/sh" *) This is some trivial shell script we'd like to source:
code = "#! " <> myshell <> "\nhi () {echo \"Hello World\";}" alias "#! /bin/zsh hi () {echo \"Hello World\";}"
that we can export directly to an external file (inside for example home directory):
Export["~/file2source", myls='ls'code, "String"]; Then in MMAThese are different ways to source the script in the file:
1.
RunProcess[$SystemShellRunProcess[myshell, "StandardOutput", "source ~/myaliasfile2source ; alias"]hi "]
Hello World
returns2.1
process = StartProcess[myshell]; WriteLine[process, "source ~/file2source ; hi"]; ReadLine[process] WriteLine[process, "exit"];
myls='ls'Hello World
which shows2.2
process = StartProcess[myshell]; WriteLine[process, "source ~/file2source ; hi ; exit"]; ReadString[process]
Hello World
Comment: It seems there is a problem with the file has been sourcedapproach consisting in reading the buffer !(like ReadString[process, EndOfBuffer]) when the command is contained in a notebook cell with other commands ... I'll explain that in a different post.