Download presentation
Presentation is loading. Please wait.
Published byMargaret Parker Modified over 9 years ago
2
What is a shell? A shell script? Introduction to bash Running Commands Applied Shell Programming
3
a command-line interpreter or An area that provides a traditional user interface for the Unix operating system Users may direct the operation of the computer by entering commands as text for a command line interpreter to execute, text scripts may be created comprising of one or more such commands.
4
INPUTshellOUTPUTERROR
5
/bin/sh /bin/bash “Bourne-Again Shell” C Shell ( /bin/csh ) Turbo C Shell ( /bin/tcsh ) Korn Shell ( /bin/ksh )
6
A Text File With Instructions Executable
7
% cat > hello.sh <<MY_PROGRAM #!/bin/sh echo ‘Hello, world’ MY_PROGRAM % chmod +x hello.sh %./hello.sh Hello, world www.wfu.edu/~borwi cjh/presentations/UN IX%20Shell- Scripting%20Basics. ppt
8
$ cat > hello.sh echo ‘Hello, world’ $ chmod +x hello.sh $./hello.sh Hello, world
9
% cat > hello.sh Clear ls -al echo ‘Hello, world’ ^z % chmod +x hello.sh %./hello.sh Hello, world
10
% hello.sh bash: hello.sh: Command not found % PATH=“$PATH:.” % hello.sh Hello, world
11
$ echo ‘$USER’ $USER $ echo “$USER” yourname % echo “\”” ” % echo “deacnet\\sct” deacnet\sct % echo ‘\”’ \”
12
% env […variables passed to sub-programs…] % NEW_VAR=“Yes” % echo $NEW_VAR Yes % env […PATH but not NEW_VAR…] % export NEW_VAR % env […PATH and NEW_VAR…]
13
$ echo Let us \ see \ A \ Very \ Long \ Command Line Let us see A Very Long Command Line $
14
$? 0 is True $ ls /does/not/exist $ echo $? 1 0
15
% test 1 -lt 10 % echo $? 0 % test 1 == 10 % echo $? 1 Test may be replaced by [ ] ◦ [ 1 –lt 10 ]
16
-eqNumeric Equalityif [ "$foo" -eq "9" ] -neNumeric Inqualityif [ "$foo" -ne "9" ] -ltLess Thanif [ "$foo" -lt "9" ] -leLess Than or Equalif [ "$foo" -le "9" ] -gtGreater Thanif [ "$foo" -gt "9" ] -geGreater Than or Equalif [ "$foo" -ge "9" ] -zString is zero lengthif [ -z "$foo" ] -nString is not zero lengthif [ -n "$foo" ] -ntNewer Thanif [ "$file1" -nt "$file2" ] -dIs a Directoryif [ -d /bin ] -fIs a Fileif [ -f /bin/ls ] -rIs a readable fileif [ -r /bin/ls ] -wIs a writable fileif [ -w /bin/ls ] -xIs an executable fileif [ -x /bin/ls ]
17
Joining conditions with and / or [ -f /etc/passwd –a –f /etc/shadow ] [ -f /etc/passwd –o –f /etc/shadow ]
18
% echo $(( 1 + 2 )) 3 % echo $(( 2 * 3 )) 6 % echo $(( 1 / 3 )) 0
19
if something then : # “elif” a contraction of “else if”: elif something-else then : else then : fi
20
if [ $USER –eq “borwicjh” ] then : # “elif” a contraction of “else if”: elif ls /etc/oratab then : else then : fi www.wfu.edu/~borwi cjh/presentations/UN IX%20Shell- Scripting%20Basics. ppt
21
# see if a file exists if [ -e /etc/passwd ] then echo “/etc/passwd exists” else echo “/etc/passwd not found!” fi
22
Check if a file exists or not
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.