-----Original Message-----
From: Catalin Bucur <[EMAIL PROTECTED]>
To: Linux Newbie Mailing List <[EMAIL PROTECTED]>
Date: Saturday, December 12, 1998 10:20 AM
Subject: HOWTO create scripts
>Hello guys,
>
>Where can I find a manual or something which can help me to create
>scripts for RedHat? I mean with some examples and hints...
>
>Thanks,
>Cata.
Sorry Catalin, sent this twice, but I figured out that a reply to all
actually puts this on the newbie list.. How clever!
Hi Everyone,
Maybe I can actually help you now, what a switch! I have a few examples
of shell scripts, but it depends on what shell you use.. Plus, it depends
on what you know and what you want to know, but I'll include a few examples
for BASH, as that seems to be the most widely used Shell for Linux.
One nice command to know, is 'export'.
i.e.,
myfile="/root/.script"
export myfile
./myfile
This creates a variable, representing a file.. This way you can easily
select which file you want to execute by simply changing the value. The
second line designates myfile as an environment variable, which is crucial..
If you or any user creates a new shell, this variable is passed up to that
shell. If the file "/root/.script" is made executible, you've basically
created a command for Unix.. Is this the sort of thing you want to know?
If you want to see what shell you are using, you can type:
echo $SHELL
You can incorporate this into scripts easily.. SHELL is an environement
variable much like the one created atop, and the preceding $ character tells
unix to look at the value of SHELL. SHELL is a pointer to a value, $SHELL
is the value within the memory location stored in SHELL.
There are other useful environment variables like PATH, MAIL, HISTFILE,
HISTSIZE, ENV, LOGNAME, CDPATH, WWW_HOME..
If you eventually want to create your own shell, you can personalize your
terminal with PS1 and PS2 (Primary & Secondary Prompt Symbols). Basically
change the prompt like: PS1="->"
There are codes to add special strings to the prompt as well:
\ Current Date. \ User Name
\ Current Working Directory
Do you need to know input/output??
echo Hello # prints Hello
lsf='ls -F' # Create a string
echo $lsf # print value in lsf
greeting="Hello there"
echo "To print a string, plus the value within $greeting"
# Requires double quotes to print values of variables
# Try it with single quotes, it is still valid, but output is different
read greeting
echo "You entered $greeting"
Is this the sort of info you are looking for?? If you want to know
something more specific, I'll be happy to pick my brain.. You caught me in
a good mood today, Manchester United lost!!!
Rob.