I have write a script, and I like to now to make it better readable, by moving parts of my main script in other files, but unfortunately I cannot.
Let's say now I have the following code in file utils.sh:
#!/bin/bash
sayHello ()
{
echo "Hello World"
}
Them from my main script I try the following, but doesn't work:
#!/bin/bash
./utils.sh
sayHello
So, the question is, how to call the functions from within the utils.sh ?
You have to source it, with . or source:
~$ cat >main.sh
#!/bin/bash
. ./utils.sh #or source ./utils.sh
sayHello
And then
~$ ./main.sh
Hello World
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With