run a command in shell script code example
Example 1: linux script to run commands
#1. Open the terminal. Go to the directory where you want to create your script.
#2. Create a file with . sh extension.
#3. Write the script in the file using an editor.
#4. Make the script executable with command
chmod +x <fileName>.
#5. Run the script using
./<fileName>.
Example 2: how to execute a bash script in terminal
$ chmod +x fileName
$ ./fileName
Example 3: how to run shell script
include
#!/bin/bash (1st line inside yourfile.sh)
to run
./yourfile.sh
if you do not include that line
bash yourfile.sh
Example 4: how to run shell script
# method 1
chmod +x <filename>
./<filename>
# method 2
sh <filename>.sh
# method 3 (Only for bash script)
bash <filename>.sh
Example 5: how to run shell script
bash yourfile.sh