Title: how to create shell scripts - creating new command script file
Description: this is a tutorial to help you get started in creating your own and very first linux shell script step by step instructions with commands Linux Hosting
Tags: linux,shell,command,tutorial,steps,script,instructions,help
Info: This Post Has Been Viewed 4229 Times SinceThu Aug 31, 2006 5:33 pm Author unix With 1 Replies #335

how to create shell scripts - creating new command script file

One of the most basic and useful program tools in the shell itself. Its also a powerful programming environment

Step 1. Type the following command to create a new file:
     Code:
cat > new_script


Step 2. Type the following lines:

     Code:
echo Your files are
ls
echo today is
date
Press ENTER to move the cursor to a new line and press CTRL-D. At this point, the file new_script contains a series of shell commands.

Step 3. Examine the file to be certain it is correct:

     Code:
cat new_script
If there are errors, remove the file new_script and return to step 1 to create it again.

Step 4. Try to run the script by entering its name:

     Code:
new_script
It doesn't run because its not executable.

Step 5. Display the permission of the file by entering:

     Code:
ls -la new_script
Notice that the file is not executable. You must make it executable.

Step 6. Type the following command to make new_script executable:

     Code:
chmod +x new_script


Step 7. To see the new permission, enter:

     Code:
ls -l
You now have execute permission, as well as read and write permissions for the file.

Step 8. Execute the new script by typing its name:

     Code:
new_script
All 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:

     Code:
Command not found
Type the following:
     Code:
./new_script
This command line tells the shell exactly where to find the shell script, new_script, in your current directory knows as "dot."
Comments (1)
View Top Comments
Leave Your Comments...
#1
webmasters245:
3 years ago
#77994
webmasters245 Tue Oct 28, 2008 9:31 am
thank you i always wanted to know how to make an executable script
Share
| More