Unix Forever

Source

Unix Rocks!

Why does Unix rock? Well, I happen to feel comfortable with this scripting language. It is easy to learn and use, and the code is easily understood, even for beginners. Unix, as an operating system and scripting language, goes all the way back to 1969. I won't bore you with details on the history on Unix.


below is an example of using a variable in the unix scripting language:


MY_MESSAGE="Hello World"

echo $MY_MESSAGE


The above example couldn't get any simpler; It prints the words Hello World. "Hello World" is usually what people start off with when they first start to learn a programming language. In other words, when you learn ASP, you will probably start off by creating a "Hello World" type of program to start with.


The example below is somewhat more complicated. The terminal asks for your user name, and it will create a file based on the answer you type.


echo "What is your name?"

read USER_NAME

echo "Hello $USER_NAME"

echo "I will create you a file called ${USER_NAME}_file"

touch "${USER_NAME}_file"


The touch command creates an empty file. If a particular file already exists- its current contents will be destroyed and it will be replaced with a blank file. If you type 'Ben' as your user name, the file 'Ben_file' will be created.


The final unix sample code I'll give for this Hub involves looping. Looping enables you to repeat a task many times without having to type a lot of code. The following loop example is a 'For' loop.


for

loops iterate through a set of values until the list is exhausted:

for i in 1 2 3 4 5

do

echo "Looping ... number $i"

done


You should try this on a terminal and see for yourself what the result will be. The above code will produce this result:


Looping .... number 1

Looping .... number 2

Looping .... number 3

Looping .... number 4

Looping .... number 5


Comments

No comments yet.

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working