Linux Programming: Difference between revisions
Jump to navigation
Jump to search
Line 17: | Line 17: | ||
== Conditions == | == Conditions == | ||
<pre> | |||
if [ -f fred.c ] | |||
then | |||
... | |||
fi | |||
if [ -f fred.c ]; then | |||
... | |||
fi | |||
</pre> | |||
Arithmetic comparison | |||
<pre> | |||
expr1 -eq expr2 | |||
expr1 -ne expr2 | |||
expr1 -gt expr2 | |||
expr1 -ge expr2 | |||
expr1 -lt expr2 | |||
expr1 -le expr2 | |||
! expr | |||
</pre> | |||
File conditionals | |||
<pre> | |||
-d file ==> True if the file is a directory | |||
-e file ==> True if the file exists | |||
-f file ==> True if the file is a regular file | |||
-r file ==> True if the file is readable | |||
-s file ==> True if the file has non-zero size | |||
-w file ==> True if the file is writable | |||
-x file ==> True if the file is executable | |||
</pre> | |||
== Control Structures == | == Control Structures == | ||
== Functions == | == Functions == |
Revision as of 10:04, 21 April 2014
Shell Programming
Variables
food=Banana echo $food food="Apple" echo $food $HOME $PATH $0 -- name of the shell script $# -- number of parameters passed $$ process ID of the shell script, often used inside a script for generating unique temp filenames $1, $2, .... -- parameters given to the script $* -- list of all the parameters, in a single variable $@ -- subtle variation on $*
Conditions
if [ -f fred.c ] then ... fi if [ -f fred.c ]; then ... fi
Arithmetic comparison
expr1 -eq expr2 expr1 -ne expr2 expr1 -gt expr2 expr1 -ge expr2 expr1 -lt expr2 expr1 -le expr2 ! expr
File conditionals
-d file ==> True if the file is a directory -e file ==> True if the file exists -f file ==> True if the file is a regular file -r file ==> True if the file is readable -s file ==> True if the file has non-zero size -w file ==> True if the file is writable -x file ==> True if the file is executable
Control Structures
Functions
Commands
Command Execution
Debugging Scripts
Working with Files
UNIX environment
Logging
Resources and Limits
Curses
A technique between command line and full GUI.
Example: vi.