I am using bash on Mac OSX.I have a shell file named myshell.sh and I use it to do a lot of things.I have a entrance.sh file which contains:# content of entrance.sh./myshell.sh arg1 arg2./myshell.sh arg3 arg4But when I run entrance.sh I got a error:./entrance.sh: line 2: myshell.sh: command not foundI can run the myshell.sh directly.What can I do?
How to run a shell script inside a shell script
bash
./myshell.sh means the script myshell.sh is found in the current directory. If you run this script from somewhere else, it won't work. You could use full paths, but in this case, the only sensible solutions are:Adding the location of myshell.sh to your $PATH (in case, myshell.sh really is something that is supposed to be called from everywhere). So, add PATH=$PATH:/dir/of/myshell at the beginning of the outer script.Put myshell.sh somewhere so that it's accessible from everywhere (just like all other executables on the system). That would be /usr/local/bin most likely. Use this only if this script is universally useful.If the scripts rely on local files in their directory (and may even break down and do damage if called from elsewhere), then you should either leave it in the current form (this actually prevents you to call them from places you are not supposed to), or use cd inside the script to get to the proper location. Be careful, use absolute paths in shell scripts for cd, it is too easy to break stuff if something goes wrong and you go out .. and cd-ing further in fails, you could escape out of your directory and reign chaos all over the parent directories.Mostly I'd recommend solution #1.