- Forums
- Linux Systems
- How To Create A Shell Script - Creating A Shell Script From The Linux Shell Command
This Page Contains information about How To Create A Shell Script - Creating A Shell Script From The Linux Shell Command By lini in category Linux Systems with 3 Replies. [2899], Last Updated: Sat May 18, 2024
lini
Thu May 03, 2007
3 Comments
1442 Visits
PROGRAMMING WITH UNIX TOOLS -
you can use UNIX to program in a variety of formats and languages. the UNIX operating sytem gives programmers a number of programming tools that either are packaged with the sytem or that can be added.
CREATING A SHELL SCRIPT -
One fo the most basic and useful program tools in the shell itself. you may be familiar with the shell asn an interactive command interprete. it is also a powerful programming environment, follow these steps to create a simple script.
STEP 1.
type the following command to create a new file called new_script
cat > new_script
type the following lines:
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 2.
take a look at the file to make sure it has the lines you entered:
cat new_script
if there are any errors, delete new_script file and start again from step1.
STEP 3.
now try to run the script with this command:
new_script
it does not work
STEP 4.
display ther jpermission of the file by entering this command:
ls -l new_script
the permissions indicated that the file is not executable. to run the script by simply calling its name, you must grant yourself execute permission.
STEP 5.
Type the following command to make new_script executable:
chmod +x new_script
OR, you can also use this
chmod 755 new_script
STEP 6.
confirm ther permission have been set
ls -l
you now have execute permission, as wll as read and write permissions for the file.
STEP 7.
execute the new script by typing its name;
new_script
all the commands that you typed into the file are executed, and their output is sent to the screen.
if for some reason you get an error that says:
command not found
type the following command:
./new_script
this command line tells the shell exactly where to find the shell script, new_script, in your current directory known as "dot."