Presentation is loading. Please wait.

Presentation is loading. Please wait.

Shells. Variables MESSAGE="HELLO WORLD" echo $MESSAGE MESSAGE="HELLO WORLD $LOGNAME" echo $MESSAGE MESSAGE="HELLO WORLD $USER" echo $MESSAGE.

Similar presentations


Presentation on theme: "Shells. Variables MESSAGE="HELLO WORLD" echo $MESSAGE MESSAGE="HELLO WORLD $LOGNAME" echo $MESSAGE MESSAGE="HELLO WORLD $USER" echo $MESSAGE."— Presentation transcript:

1 Shells

2 Variables MESSAGE="HELLO WORLD" echo $MESSAGE MESSAGE="HELLO WORLD $LOGNAME" echo $MESSAGE MESSAGE="HELLO WORLD $USER" echo $MESSAGE

3 comment #this is a comment #this just prints to screen echo hello mum save this as hello.sh change permissions run as sh hello.sh

4 utilities and commands a utility is a program, a command is an instruction uname -a > outputfile.txt (will display vital statistics on the system.)

5 Five different types of command simple command pipeline list command function definition compound command

6 Grouping Commands (echo start ; cat hello.sh ; echo end) > new.txt adds start and end to hello.sh command1 || (command2 && command3)

7 Exit Status 0 if previous command successful non zero if previous command not successful chmod u-w testfile cat > testfile echo $? 1

8 basic calculator bc 1+2 100/3 scale=5 (5 decimal places) sqrt(2)

9 operations + addition - subtraction * multiplication % integer remainder ^ power

10 Functions sqrt length scale (need option -l for library) s, sine c, cosine a, inverse tanget e, exponetial l, natural logarithm. echo "1+2" | bc echo 2/3 | bc –l (-l is better!!!!).66666666666666666666

11 The Test Statement two ways test arguments [arguments] [ -e ouput.txt ] && echo file exists if the file exists, echo the message [ -e ouput.txt ] || echo file not exist if the file does not exist, echo the message

12 If…file exists test -e ouput.txt && echo file exists if the file exists, echo the message test -e ouput.txt || echo file not exist if the file does not exist, echo the message

13 File operators used by test -d, if exists and is directory -e, if exists -f, if exists and is regualar file -r, if exists and is readable -s, if exists and has non-zero size -w, if exists and is writable -x, if exists and is executable

14 String operators used by test -n, if string has non-zero length -x, if string has zero length string, if string is not null s1=s2, if strings are equal s1!=s2, if strings are different.

15 Example – NAME not set $ [ "$NAME" ] || echo NAME not set NAME not set $ [ $NAME ] || echo NAME not set NAME not set

16 Arithmetic Operators used by test -eq, equal -ne, not equal -gt, greater than -ge, greater than or equal to -lt, less than -le, less than or equal to.

17 Example -eq and = 0 and 00 are numerically equal $ [ 0 -eq 00 ] && echo equal equal 0 and 00 are different strings. $ [ 0 = 00 ] && echo equal $

18 White Space is important # [ "0" -eq "00" ] && echo equal equal # [ "0" -eq "00"] && echo equal bash: [: missing `]'

19 IF statement if [ hell = hell ] then echo equal else echo not equal fi if [ hell1 = hell2 ] then echo equal else echo not equal fi

20 For Loops for name in values do commands done

21 For loop example for i in $( ls ) do [ -r $i ] && echo $i is readable done

22 While Loops while true do echo tick tock (this the sound of a clock) date sleep 1 done

23 Until Loops until command1 do command2 done


Download ppt "Shells. Variables MESSAGE="HELLO WORLD" echo $MESSAGE MESSAGE="HELLO WORLD $LOGNAME" echo $MESSAGE MESSAGE="HELLO WORLD $USER" echo $MESSAGE."

Similar presentations


Ads by Google