Method One: Switch to the directory where the shell script executes the shell script:
cd/data/Shell. /hello.sh
The./means to execute hello.sh under the current working directory. If you do not add./,bash may respond to an error message that could not be found hello.sh. Because the current working directory (/data/shell) may not be the default search path for the executing program, that is, it is not in the contents of the environment variable pash. The Echo $PASH command is available to view the contents of the path. Now the/data/shell is not in the environment variable pash, so you must add./To execute.
Method Two: Execute the Bash shell script in an absolute path:
/data/shell/hello.sh
Method Three: Use bash or sh directly to execute the Bash shell script:
cd/data/Shellbash hello.sh
Or
cd/data/shellsh hello.sh
Note that if you do this in method three, you do not have to set the execution permissions of the shell beforehand, or even write the first line in the shell file (specify the bash path). Because method three is performed by passing hello.sh as a parameter to the SH (bash) command. This is not hello.sh to execute itself, but is called by others to execute, so do not execute permissions. Then you don't have to specify the bash path.
Shell Script Execution