Monday, December 31, 2012

Working with korn shell

Working with korn shell
1.
Following are the built-in shell variables and their descriptions:

  • # : Specifies the number of arguments allocated to the current process.
  • : Shows the option specified to the shell when it is invoked.
  • ? : Shows the exit status of a specified command.
  • $: Shows the process ID of a shell process.
  • !: Shows the process ID of the last background command.
  • CDPATH: Shows the list of directories to search the cd command.
  • COLUMNS: Shows the width of the display in columns and lets you edit modes.
  • EDITOR: Lets you edit modes.
  • ERRNO: Shows the error number of a failed system call.
  • ENV: Shows the name of the file run as an environment file.
  • FCEDITL: Shows the default editor for the fc command.
  • FPATH: Let's you search a path for an automated function.
  • Internal Field Separator (IFS): Shows the list of symbols that act as word delimiters, such as space, tab, or a new line.
  • HISTFILE: Shows the name of the command history file.
  • OLDPWD: Shows the previous working directory.
 
2.

Input Mode Commands for the vi Editor
Command Key CombinationCommand NameDescription
IInsert modeInserts text before the current cursor position.
aAppend modeInserts text after the current cursor position.
rReplace modeReplaces the character at the cursor, one character at a time.
sReplace and insert modeDeletes the character on which the cursor is placed and overwrites it.
IBeginning lineInserts text at the beginning of the line pointed by the cursor.
AEnding lineInserts text at the end of the line pointed by the cursor.
ROverwriteOverwrites the existing text.
OBlank line belowInserts a single blank line below the line on which the cursor is currently placed. Enters the insert mode.
OBlank line upInserts a single blank line above the line on which the cursor is currently placed. Enters the insert mode.

 

Commands to Control the Cursor in vi Editor
Command KeyCommand NameDescription
hMove leftMoves the cursor one character left.
lMove rightMoves the cursor one character right.
eMove wordMoves the cursor to the end of the current word.
wMove wordMoves the cursor to the beginning of the next word towards the right.
bMove wordMoves the cursor to the beginning of the previous word towards the left.
kMove upMoves the cursor to the previous line, one line at a time.
jMove downMoves the cursor to the next line, one line at a time.
0Move beginningMoves the cursor to the beginning of the line.
^Move beginningMoves the cursor to the beginning of the first word of the line.
$Move endMoves the cursor to end of the current line.
1GMove first lineMoves the cursor to the beginning of the first line.
NGMove lineMoves the cursor to line n.
GMove last lineMoves the cursor to the beginning of the last line.
{Scroll upScrolls up half the page.
}Scroll downScrolls down half the page.

 

Scrolling Commands in vi Editor
Command Key CombinationDescription
Ctrl + fScrolls through the contents of the file one page up.
Ctrl + bScrolls through the contents of the file one page down.
Ctrl + uScrolls through the contents of the file half page up.
Ctrl + dScrolls through the contents of the file half page down.

 

Deletion Commands for vi Editor
Command Key CombinationDescription
dhDeletes previous character, one character at a time. Enters the input mode after deletion.
dlDeletes next character, one character at a time. Enters the input mode.
dbDeletes previous word, one word at a time. Enters the input mode.
dwDeletes next word, one word at a time. Enters the input mode.
ddDeletes entire line, one line at a time. This line is stored in the buffer and you can place it at the cursor position by the copy command. Enters the input mode.
nddDeletes n lines. N numbers of lines are deleted. Enters the input mode.
d$Deletes characters from the current cursor position until the end of line. Enters the input mode.
d0Deletes characters form the current cursor position until the beginning of the line. Enters the input mode.

 
 
Undo and Redo commands in vi Editor
Command Key combinationDescription
uUndoes all the previous changes in the line.
UUndoes a single previous change in the line.
. (period)Redoes last change at current cursor position.
yCopies the text in the line on which the cursor is placed.
pCopies the line selected by the copy command after the cursor.
PCopies the line selected by the copy command before the cursor.

 

Commands for Searching Text in the vi Editor
Command key CombinationDescription
?stringMatches the string with the text in the file, in back direction from the current cursor position. You need to place the string to match with the contents of the file after the question mark (?).
/stringMatches the string with the text in the file, in forward direction from the current cursor position. You need to place the string to match with the contents of the file after the back slash (/).
nRepeats the search in the same direction as that of the previous search.
NRepeats the search in the opposite direction as that of the previous search.

 
3.
In the Korn shell, an array variable is also called an indexed array. The Korn shell does not perform array-bound checks, which implies that an array can hold more array variables as the size of an array increases. Unlike other programming languages, such as C and C++, the Korn shell does not hold any junk value for an un-initialized array variable.
An index number represents each element of an array. The index number of the first element in an array is zero (0). The upper limit of the index is the total number of elements that an array variable can hold.
$ typeset -u number[6]
$ number[0]=70
$ echo ${number[0]}
$ firstname[0]="John"
$ echo ${firstname[0]}
Another method to assign values to an array is to assign all the values in a single statement. The syntax to assign values to multiple elements of an array in a single statement is:
$ set  -A firstname "John" "Paul" "Smith"

You can access more than one value from an array in a single statement. The syntax to access multiple values from an array in a single statement is:
${variablename[*]}
The command to access the elements of an array is:
$ echo ${firstname[*]}
 ksh histroy 列出所有历史命令
然后,r 命令号 即可执行选定的历史命令
Esc+k 列出上一条  Esc+\ 补齐
for username in $(cat $PASSWORD_FILE | cut -f1 -d:)
do
  print $username
done
查看Solaris CPU个数:
prtdiag -v (还可看内存 top)
psrinfo -v
uname -X
sed -e '/^#/d' /etc/services | more
sed -e 's/foo/bar/g' myfile.txt

vi
w b 单词往前/后移动
{ } 句子往前/后移动
向前重复搜索,按 n 键。要向后搜索,按 N 键
输入 :w filename.txt 便可另存为 filename.txt
J 命令将下一行接到当前行行末。现在,将光标移到一个字符并敲 r,然后输入新字符;您将看到原字符被替换掉
3dd dw 4J
O (大写)在当前行上面生成一空行
d3w 将删除光标后 3 个单词,d2j 将删除当前行和下两行

对于 Korn Shell 用户,文件名完成取决于 EDITOR 变量的值。如果 EDITOR 设置为 vi,那么您键入部分名称,然后按 Esc 键,后跟反斜杠 (\) 字符。如果 EDITOR 设置为 emacs,那么您键入部分名称,然后按两次 Esc 键以完成文件名。
怎么拼? how do you spell?
查看操作系统是64位还是32位         isainfo -kv

No comments:

Post a Comment