انت هنا الان : شبكة جامعة بابل > موقع الكلية > نظام التعليم الالكتروني > مشاهدة المحاضرة

Linux, Shell Script Lecture notes 2

الكلية كلية تكنولوجيا المعلومات     القسم قسم البرامجيات     المرحلة 4
أستاذ المادة جورج اسكندر حسين موسى       08/11/2012 21:02:41
Shell Scripting -2

* File Permission
* Variable
* Quoting
* Environment Variables
* Conditional If Statement
File Permission
* We’ve noticed that files in Linux have special formatting, so when we create a text file and write a script in it, it remains a text! So in order to make it executable we’ve made a change to its mode so that it would become executable by using:
Chmod a+x testfile
So, to work with permissions we need to understand the following:
Each file has 3 possible actions (Read, Write & eXecute) RWX
And 3 possible kind of permissions can be granted to
User (The owner), Group, Other
So if we need to put that in an example that makes testfile executable only by the owner we may user
Chmod u+x testfile
While using the other method by numbers which is used widely in representing permissions in web servers.
Like chmod 700 testfile which mean make testfile RWX only for the user
U G O
R W X R W X R W X
4 2 1 0 0 0 0 0 0
7 0 0
Variables
* Variables needed to be declared, note it is case-sensitive (e.g. foo, FOO, Foo)
* Add ‘$’ for storing values
% i=Hallo
% echo $i
Hallo
% x=7+5
% echo $x
7+5
% y=“yes dear”
% echo $y
yes dear
% read s
Hallo!
% echo $s
Hallo!
Quoting
* Edit a “testfile.sh” file
#!/bin/sh
myvar=“Hi there”
echo $myvar
echo “$myvar”
echo `$myvar`
echo \$myvar
echo Enter some text
read myvar
echo ‘$myvar’ now equals $myvar
exit 0

Environment Variables
* $HOME home directory
* $PATH path
* $PS1 (normally %)
* $PS2 (normally >)
* $$ process id of the script
* $# number of input parameters
* $0 name of the script file
* $IFS separation character (white space)
Use ‘env’ to check the value.

Condition

So the syntax of If statement:

Condition Structure


Home Work
Write a shell script that check weather a file called mytest.sh is in the home directory, then read form the user an input and write that input to the file mytest.sh.
Please email George. ejaam at gmail . com the answer no later than 14-11-2012 10:00 PM.
Thanks


المادة المعروضة اعلاه هي مدخل الى المحاضرة المرفوعة بواسطة استاذ(ة) المادة . وقد تبدو لك غير متكاملة . حيث يضع استاذ المادة في بعض الاحيان فقط الجزء الاول من المحاضرة من اجل الاطلاع على ما ستقوم بتحميله لاحقا . في نظام التعليم الالكتروني نوفر هذه الخدمة لكي نبقيك على اطلاع حول محتوى الملف الذي ستقوم بتحميله .