Sunday, April 28, 2024
8
rated 0 times [  8] [ 0]  / answers: 1 / hits: 3147  / 2 Years ago, tue, february 22, 2022, 3:34:22

I've got an executable, let's call it exec. It lives in a directory, for the sake of argument called dir. Let's say it's at the filesystem root. I can run this executable by doing



cd /dir
./exec


If I try to run it from anywhere else, by doing



/dir/exec


it fails to run. From the error message it spews out, it looks like it's trying to look for support files in the directory from which the command was run, not in its own directory. So far not a massive problem. However, I'd like to alias the command so I can call it from anywhere. I can write an alias as follows:



alias foo="cd /dir;./exec &"


But that leaves my terminal in /dir, which I don't want. I also don't want to change back to some arbitrary directory, I want to stay where I was.



Can this be done?


More From » command-line

 Answers
4

Yes, launch another shell:



alias foo="sh -c 'cd /dir; ./exec &'"


Or use a subshell:



alias foo="(cd /dir; ./exec &)"

[#33135] Wednesday, February 23, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
istmasted

Total Points: 287
Total Questions: 130
Total Answers: 153

Location: Burkina Faso
Member since Thu, Dec 23, 2021
2 Years ago
istmasted questions
;