Dimon
Dimon

Reputation: 436

execute a directory in linux

I would like to execute a directory like this: './some_directory some_args'. In that some_directory there can be a script that grabs these some_args, processes them and passes them to a binary executable or other script located in the same directory. Basically, I want to run a script in some_director without specifying its name. There is got to be a default script to run I guess when doing './some_directory some_args' in bash or other shell. Thanks.

So I ended up using python and __main__.py script in this directory. You run it like this:

python ./directory

Upvotes: 0

Views: 715

Answers (3)

Dimon
Dimon

Reputation: 436

python and __main__.py script in the directory. You run the directory like this: python ./directory

Upvotes: 1

Mark Reed
Mark Reed

Reputation: 95252

Executing a directory is nonsensical in Linux terms; you could perhaps set something up to fake it (e.g. autocd + prompt_command code), but it would just be confusing to any users who are familiar with Linux norms.

I would recommend instead that you install a script to start your application into a standard location, with the name of the app and no suffix. For example, the command /usr/local/bin/myapp just runs /path/to/myapp/startscript.py, and users can invoke it by simply typing myapp.

Upvotes: 0

paulmelnikow
paulmelnikow

Reputation: 17208

You can't execute a directory. Directories don't have default scripts. You need to put the path to the script on the command line.

Depending on why you're trying to do this, you could look at using a shell alias.

Upvotes: 2

Related Questions