Ways to execute bash script without "./"? [duplicate] - bash

This question already has answers here:
How do I run a shell script without using "sh" or "bash" commands?
(13 answers)
How to enable a system-wide function for users including sudo?
(2 answers)
Closed 3 years ago.
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

Related

Find out what the (shell) script was invoked with [duplicate]

This question already has answers here:
How do I parse command line arguments in Bash?
(40 answers)
How to get exact command line string from shell?
(2 answers)
Closed 3 years ago.
Suppose my script.sh could take a number of options and arguments. What is the best way to find out what the script was invoked with (form inside the script)?
For eg., someone called it with script.sh --foo_option bar_arg
Is there a way to echo that exact command they typed from inside the script?
I've tried echo !! which does not work inside a script.

Programmatically add functions to a user's bash profile [duplicate]

This question already has answers here:
How to install a bash function containing variables using a bash script? [duplicate]
(2 answers)
Create a script that adds lines of code to .bashrc then reloads the terminal
(2 answers)
Closed 4 years ago.
I've written a very simple utility to allow a couple of colleagues to easily access some system logs.
The dependencies for this are installed by running a curl to an install.sh file on GitHub.
There are a couple of functions and aliases that are handy to have in your bash profile. Out of interest how would I programmatically add items to a user's bash profile in a shell script.

bash script, execute command line and keep going the next for loop [duplicate]

This question already has answers here:
Loop background job
(3 answers)
Closed 4 years ago.
Is it possible to run a command in a for loop without waiting for that command ended, while keeping going to the next iteration?
Because I have to send multi-files at the same time asap via many ssh connections, therefore I couldn't wait until the command ended one by one.
Maybe is it related to something like 'xterm' or 'gnome-terminal'?
Yes, you can execute the command in background by adding & at its end.
So the syntax looks like programName [arguments] & (at least for bourne compatible shells)

Run in parallel from bash [duplicate]

This question already has answers here:
How do you run multiple programs in parallel from a bash script?
(19 answers)
Closed 6 years ago.
I have this bash script:
#!/bin/bash
for i in `seq 1 10`;
do
./Hysto file$i.txt
done
I am completely new to parallel programing and even bash language but i meant by this code to run 10 jobs in parallel (I have more than 10 cores available). The program in meant to save data to some files (which don't depend on each other). However in the folder where the files are supposed to be created they appear one by one (the output of file1.txt, then file2.txt and so on), so I assume they are not run in parallel. Can you tell me how can I write a bash file so I can run my jobs in parallel?
All you need to do to run in parallel in bash is to put an & at the end of your command. Here you'd put it after .txt.
See also: How do you run multiple programs in parallel from a bash script.

Launch shell script from another script [duplicate]

This question already has an answer here:
Running several scripts in parallel bash script [duplicate]
(1 answer)
Closed 7 years ago.
I have the following shell script
#for i in {0..10}
do
run my command that takes about 10 seconds with parameter $i
done
How can I get this to run the commands in parallel without using GNU Parallel as I am not able to install it on my linux box.
Is there a way I can create 10 different shell scripts and call them e.g. script_1.sh, script_2.sh, script_3.sh etc and then launch them one by one from this script?
You could use an ampersand (&) and launch script.sh $1 & ten times. This will make the script run in a fork of the main process. It is an easy way to do parallel processing but definitely not very flexible and doesn't have many features. A simple tutorial can be found here.

Resources