V
V
vasIvas2016-02-15 12:38:04
linux
vasIvas, 2016-02-15 12:38:04

How to execute a file in console using bash?

There is a directory with many directories, one of which contains a file. And very often you have to go into this directory, launch a console from it, then drive in the path to the file in the console ...
How many times I wanted to ask this question, but stopped myself. And now, once again, I decided to ask anyway - can I write a bash command so that by clicking on the file all of the above is done without my participation? If possible, how?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Sergey, 2016-02-15
@vasIvas

taken from here: https://github.com/jlevy/the-art-of-command-line
In Bash scripts, subshells (written with parentheses) are convenient ways to group commands. A common example is to temporarily move to a different working directory, eg

# do something in current dir
(cd /some/other/dir && other-command)
# continue in original dir

Possible solution:
you can add alias to ~/.bashrc:
alias my_command='(cd /path/to/dir && ./my_command)'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question