How To Run Bash Script In Linux?

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/run-bash-script-linux/
PINTEREST
PINTEREST
INSTAGRAM

Bash is the heart of the linux. Most of times bash commands are used to create a script and execute regularly. But the question is how can we run bash scripts in linux in different ways? We will look different ways to make bash script executable and run in linux

Script File

Script file holds required commands those will run in bash. Script file generally have .sh extension and file content starts with #!/bin/bash but keep in mind if the shell is not bash the interpreter will be change. Here is simple example shell file.

Make Sh File Executable

We can run shell script files directly like a command if we make them executable. Executable is a permission to run files as command. Current user should have execution permission for the file.

Actually the extension of the file is not important but using general conventions will makes administrators job easy. Following extensions can be used too;

  • sc
  • ksh
  • myscriptis

Add Script To The PATH

We can call script file without giving full path and just call like a Linux command.Linux use $PATH variable to locate commands. We can add our script file path to the $PATH variable and call without full path.

Run Script With Bash Command

We can run script files without making them executable or change anything. bash command can be used to interpret the script file and run scripts inside it.

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/run-bash-script-linux/
PINTEREST
PINTEREST
INSTAGRAM

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)