For instance when reading from a file you want to exclude all the comments i.e. lines beginning with hash sign (#), then use -v switch for grep command:
grep -v "^\#" $FILENAME
grep -v "^\#" $FILENAME
vi myscript.kshKorn shell scripts usually have extension ksh The first line of the script should always be:
#!/usr/bin/kshAfter the file has been created, one needs to give it execute permissions so that the file becomes runable:
chmod 755 myscript.kshNow the script can be executed as follows:
./myscript.kshif the script name or path has spaces in it, it needs to be wrapped in double quotes
"C:\My Documents\My Scripts\myscript.ksh"The escape character for ksh scripts is a (\) backslash. For example if you want to escape a dollar sign ($) inside your script, instead of writing
select * from v$database;use
select * from v\$database;(#) pound sign is used for comments and print and echo commands are used to output text to a sceen
find ./* -type f -mtime +30 -exec rm {} \;
The above will clear out files that are older than 30 days in the current directory.
find ./* will look at the current directory, grabbing all the files (*), -mtime +30 will specify files that are older than 30 days, and -exec rm {} \ will remove all the files that match the condition.
| Command | Action |
|---|---|
| x | delete one character |
| dw | delete current word |
| dd | delete current line |
| D | delete all content to the rigght of the cursor |
| :u | undo last command |
| :q | quit editor without saving |
| :wq | save and quit editor |
| :w | write without exit |
| :[n] | goto line [n] |
| b | move backwards one word |
| i | begin inserting text at the current cursor location |