if you are starting to play with linux, eventually, you will find the flexibility that the linux shell provides. it provides you with so many possibilities to manage your linux box.
in this example, we are going to create a simple text file. this file will contain the commands to run. if you are familiar with linux, you know you can send commands to the shell, for example the date command shows today's date. so we are going to save a couple of commands in a text file to run when text file is executed
ok, lets get started and login to your linux computer.
Step 1. We are going to be using the cat utility to create a simple text file. from this text file we are going to run the commands.Type the following command to create a new file:
cat > new_script
Step 2. the cat command will take you to prompt mode.. here we are going to enter the shell commands to execute in our file.. so Type the following lines:
echo Your files areNOTE: Press ENTER to move the cursor to a new line and press CTRL-D to end
echo today is
echo today is
Step 3. Check the file to be sure you typed correctly without any errors. display the contents of new_script file:
cat new_scriptIf there are errors, remove the file new_script and return to step 1 to create it again.
Step 4. Try to run the file to see if the commands will execute.
new_scriptYou will get a 'command not found' error because the files is not executable.
Step 5. Display the permission of the file by entering:
ls -la new_scriptNotice that the file is not executable. You must make it executable.
Step 6. Type the following command to make new_script executable:
chmod +x new_script
Step 7. To see the new permission, enter:
ls -lYou now have execute permission, as well as read and write permissions for the file.
Step 8. Execute the new script by typing its name:
new_scriptAll the commands that you typed into the file are executed, and their output is sent to the screen.
Step 9. If you receive an error message such as: Command not found Type the following:
./new_scriptThis command line tells the shell exactly where to find the shell script, new_script, in your current directory knows as 'dot.'
as yo can see from the script output, it lists the files in your directory and the today's date.
note, the echo command. if you are familiar with PHP, its the same idea. echo is like using print command in other programming languages.
hope this helps, check out my other tutorials for beginners