0

I have a bash script called climb.sh. When I execute it I write

./climb.sh 1

while inside the directory in which the script is located. However, I want to do the same thing wherever I am, and across all shell sessions by simply calling

climb 1

Also, climb.sh takes an numeric argument and calls "cd ../" that many times. In order for the program to work, it has to run alongside the current process, not within some child process.

How to achieve all this? Thanks

4
  • Don't use file extensions on executables. If you have a valid shebang and an execute bit set on your script, your script is an executable; just as you have /usr/bin/ls instead of /usr/bin/ls.elf, you should have /usr/local/bin/climb instead of /usr/local/bin/climb.sh. (/usr/local/bin is important because, as described in the linked duplicate, it's a location in the default search PATH environment variable used to find executables used without a / in their names specifying a specific location). Commented Sep 1, 2019 at 20:13
  • Thank you. Btw, there is something in my question that isnt duplicable. I asked the same question you proposed to be a dublicate, but for across ALL sessions. I also asked about how to make the program work in regards that it is calling "cd ../". I found out that I have to call source climb.sh. But how to make source climb default, so i need only to call climb. ty Commented Sep 1, 2019 at 21:10
  • That's a different question, and the answer boils down to "you can't" -- at least, not without participation of the users whose accounts are involved. (Such participation might mean, f/e, their shells sourceing all files in /etc/profile.d/, such that you need to put your script defining a function in a similar location -- but you'll need to look at your specific OS; there's nothing in bash itself that allows it; things like /etc/profile.d are configuration your OS vendor arranges, not functionality built into the shell). Commented Sep 1, 2019 at 21:24
  • I've added a link ("How to enable a system-wide function") that's appropriate to that end of the question; see the answer by zmo, not the accepted one. (Functions are the more-powerful alternative to aliases; any answer that might guide you to alias climb='source /usr/local/bin/climb.sh' could instead by written as climb() { . /usr/local/bin/climb.sh "$@"; }; export -f climb, installed in the same ways, but then with an impact not only on the shell it's sourced into but also that shell's children). Commented Sep 1, 2019 at 21:35

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.