Is there a standard way in a unixesque (sh/bash/zsh) system to execute a group of scripts as if the group of scripts was one script? (Think index.html). The point is to avoid additional helper scripts like you usually find and keep small programs self sufficient and easier to maintain.

Say I have two (in bold) ruby scripts.

/bin
/bin/foo_master
/bin/foo_master/main
/bin/foo_master/helper.rb

So now when I execute foo_master

seo@macbook ~ $foo_master
[/bin/foo_master/main]: Make new friends, but keep the old.
[/bin/foo_master/helper.rb]: One is silver and the other gold.

有帮助吗?

解决方案 2

I figured out how to do this in a semi-standard complaint fashion.

I used the eval syntax in shell scripting to lambda evaluate the $PATH at runtime. So in my /etc/.zshrc

$REALPATH = $PATH
$PATH = $REALPATH:`find_paths`

where find_paths is a function that recursively searches the $PATH directories for folders (pseudocode below)

(foreach path in $PATH => ls -d -- */)



So we go from this:

seo@macbook $ echo $PATH
/bin/:/usr/bin/

To this, automagically:

seo@macbook $ echo $PATH
/bin/:/usr/bin/:/bin/foo_master/

Now I just rename main to "foo_master" and voilà! Self contained executable, dare I say "app".

其他提示

If you're trying to do this without creating a helper script, the typical way to do this would just be to execute both (note: I'll use : $; to represent the shell prompt):

: $; ./main; ./helper.rb

Now, if you're trying to capture the output of both into a file, say, then you can group these into a subshell, with parenthesis, and capture the output of the subshell as if it was a single command, like so:

: $; (./main; ./helper.rb) > index.html

Is this what you're after? I'm a little unclear on what your final goal is. If you want to make this a heavily repeatable thing, then one probably would want to create a wrapper command... but if you just want to run two commands as one, you can do one of the above two options, and it should work for most cases. (Feel free to expand the question, though, if I'm missing what you're after.)

Yep that's an easy one!

#!/bin/bash

/bin/foo_master/main
/bin/foo_master/helper.rb

Save the file as foo_master.sh and type this in the shell:

seo@macbook ~ $sudo chmod +x foo_master.sh

Then to run type:

seo@macbook ~ $./foo_master.sh

EDIT:

The reason that an index.html file is served at any given directory is because the HTTP Server explicitly looks for one. (In server config files you can specify names of files to look for to server like index.html i.e. index.php index.htm foo.html etc). Thus it is not magical. At some point, a "helper script" is explicitly looking for files. I don't think writing a script like above is a step you can skip.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top