Bash Scripting | Beginner Tutorial Posted: 15 Apr 2010 02:10 PM PDT In this beginner tutorial I will show you some of the basics of shell script programming, and hopefully to introduce some of the possibilities of simple but powerful programming available under the shell.
1)MKDIR - mkdir dirname is bash command for creating folders
Example 1:
Example 2: Create folder with name of current date
Example 3: Create folder with name of current day
Example 4: Create folders using brace expansion
Example 5: make all parent directories along with their children in a single command.
$ mkdir -p programming/BASHscripting/ As you can see above, mkdir with -p option can save you a lot of time an efforts. 2)WC (word count) - wc displays a count of lines, words, and characters in a file.
- without options count Lines Words Characters
Example 1: Count lines in hackspc.txt
Example 2: Count words in hackspc.txt
Example 3: Count characters in hackspc.txt
Example 4: Count lines, words, characters
Example 5: count number of lines, words, characters from hackspc.txt and save it into filecounting.txt
3)GREP -grep command is one of the easiest methods of locating text contained within a file
Let’s look .txt file called hackspc.txt
Example 1 : find word hack in file hackspc.txt,
Output will be all lines that contains word hack
Example 2: find lines that don’t contain word hack
Output: Example 3 : find word hack in file hackspc.txt, command isn’t case sensitive
Output will be all lines that contains word hack, Hack, HACK,hAcK,HaCK… Example 4 : find lines that contains words that end with g
In this example I used regular expression , [a-z] all combinations of charachters a,b,c,d,e…z ,
4)FIND - Linux / Unix and their variants have several different ways of locating files find, locate, wheris. I mostly use find command. It offer a lot options and it can easly search for files that meet a desired criteria.
| -name true if pattern matches the current file name
-type -d (find folders) , -f (find files) -size -mtime n True if the file’s data was modified n days ago. -regex regular expression |
Example 1: Search for any file named hackspc.txt in the directory home/ivan/hackspc.com/ and any subdirectory.
$ find /home/ivan/hackspc.com -name hackspc.txt
Example 2: search for any file that is larger then 2k
$ find /home/ivan/hackspc.com -name ‘*’ -size +2k
Example 3: search folders
$ find /home/ivan/hackspc.com -type d
Example 4: Search .txt files that contains only 4 digits (dddd)
$ find /home/ivan/hackspc.com -regex “.*/[0-9][0-9][0-9][0-9]\.txt”
Output:
5)IF, ECHO, VARIABLES
Example 1: if variable a equal to 5 then print five if not then write not five
$ if [ "$a" = 5 ]; then echo “five”; else echo “not five”; fi
Example 2: If you find file called hackspc.txt in diretcory /home/ivan/hackspc.com/ then print “I found file called hackspc.txt” if not then print “File Not Found”
$ if find /home/ivan/hackspc.com -name hackspc.txt
lled hackspc.txt”; else echo “File Not Found”; fi
How To Make Your Own Dynamic Home Page Using PHP
Posted: 15 Apr 2010 04:31 AM PDT
Last time I taught you, how to create your own homepage in HTML. Today I’ll teach you how to create more dynamic home page using Personal Home Page (PHP) scripting.
Please refer to my previous article about creating your own homepage in HTML to get more clearer to web programming, you’ll be needing HTML even though you program it in PHP.
Previously in the tutorial, how to create your own homepage in HTML, we created whole the navigation bar, menu content, header and post contents in one single static page.
This time we are going dynamic, i.e. every part of your web page, header, footer, body, menu, etc are going to change dynamically. To do so we are going to load separate html file in a single html page.
Refer to the chart below for more clarification.
Index.php is the main page which must be loaded by the visitor. Header.html, menu.html, post.html are the Head banner, Menu bar and Posts/articles respectively in separate HTML file. Whilist style.css is the CSS style for all the pages that will be loading in index.php.
Simply we’ll load all the files in index.php.
Let’s start designing the layout for index.php using HTML.
Page 1
Header for the web page
Menu bar at top for pageMain content or article for your home page.
Same menubar at bottom
I used simple technique of tables to layout the index.php.
Now the layout is ready and we got the maps to assign the specific header, post, menus etc.
Let’s assign the specific file to the specific address.
Home Page
include (“header.html”);
?>
include (“menu.html”);
?>include (“post.html”);
?>
include (“menu.html”);
?>
You can see two differences from the HTML code before and after.
First difference is, which must lie inside the
tag.
What it actually does is, loading the CSS style to index.php.
It’s syntax is:
‘#’ refers to the location of your stylesheet document.
Another is four blocks of code:
include (“XXX”);
?>
The above code loads the specific html/php or web file wherever it is placed, it is actually a php code that’s why it is enclosed in or
We’ve used include (); function to call the specific file, where XXX in the example above refers to the location of the file.
Note: If all the files including sub-files contains in same directory, you don’t need to mention the URL of the file, else you must define the exact location for it.
We’ve basic layout for homepage ready. All we need is the sub-pages.
Design a good banner for your homepage using Photoshop or other Image editing software.
Create new text document with following inputs in it:
Save it as header.html.
Create another text file with following inputs:
Save it as menu.html.
Now create a another text document where your contents will be loaded,
For example,
H2 heading for the page
Here goes the main content of your web page. You can include any information about your page here.
Example for a horizontal line =
Example using ‘class’ = ‘note’:
Example using ‘class’ = ‘note’
Now let’s put in an image (that is in the same folder as this file so we don’t have to put the full path / URL
Save the above example as post.html
Now you have all the contents ready. Anything left is the styling part.
You can also create your own style in another text document and save it as filename.css (in this tutorial we’ll call it style.css).
Copy the code and paste it in stye.css that you’ve just created.
body {
background-color: #FFFFFF;
font-family: Arial, Verdana, sans-serif;
font-size: 18px;
}a { font-family: Arial, Verdana, sans-serif; font-size: 18px; color: #483D8B; text-decoration: underline}
a:hover { font-family: Arial, Verdana, sans-serif; font-size: 18px; color: #000000; background-color: #FAEBD7}
h1 { font-family: Arial, Verdana, sans-serif; font-size: 36px; color: #000000 }
h2 { font-family: Arial, Verdana, sans-serif; font-size: 24px; color: #000000 }
h3 { font-family: Arial, Verdana, sans-serif; font-size: 24px; color: #000000 }
h4 { font-family: Arial, Verdana, sans-serif; font-size: 18px; color: #000000 }
h5 { font-family: Arial, Verdana, sans-serif; font-size: 12px; color: #000000 }
h6 { font-family: Arial, Verdana, sans-serif; font-size: 8px; color: #000000 }hr{ color:brown; background-color:tan; width:90%; height:2px; }
table { font-family: Arial, Verdana, sans-serif; font-size: 18px; color: #00008B; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px}
.note { font-family: Arial, Verdana, sans-serif; font-size: 14px; color: purple;
font-weight: bold;}
Save it in style.css.
I’ve applied the styling for only body, horizontal rule(hr), table and custom class named note.
Your final page will have the format similar to below:
You can add and replace the menu.html and other without opening index.php this is what makes your page handling experience some what dynamic.
Hope you liked this tutorial.
No comments:
Post a Comment