Korn Shell(K Shell) Notes (I)

Korn Shell Notes

1 Useful Cmds

wc - display a count of lines, words and characters in a file.
    It can be used to count the numbers together with other commands, such as ls, who and so on.

cut - cut out selected fields of each line of a file.
    The name of each unique user that is logged on is displayed using this command:
        $ who | cut —f1 —d' ' | sort —u
        anatole
        root

print is a Korn shell specialized command which is similar to echo.

nl - line numbering filter.

2 Conditional Execution

You can implement a simple if command by using the && and || operators together like this:
            command1 && command2 || command3
If command1 returns true, then command2 is executed, which causes command3 to not be executed. If command1 does not return true, then command2 is not executed, which causes command3 to be executed.

3 Grouping Commands

Commands enclosed in {} are executed in current shell. If
        $ echo "This is file temp:" ; cat temp | nl
        This is file temp:
        1 The rain in Spain
        2 falls mainly on the plain
then by using {}s, the output will be:
        $ { echo "This is file temp:"; cat temp ; } | nl
        1 This is file temp:
        2 The rain in Spain
        3 falls mainly on the plain
There must be whitespace after the opening {, and commands within the {}'s must be terminated with a semi-colon.

Commands enclosed in () are executed in a subshell. Subshells are generated whenever you enclose commands in ()'s, perform command substitution, for background processes, and for coprocesses.A subshell is a separate copy of the parent shell, so variables, functions, and aliases from the parent shell are available to the subshell. However, subshells cannot change the value of parent shell variables, functions, or aliases.

4 Redirecting Standard Output

By using the > symbol, the standard output of a command can be redirected to a file, instead of your terminal.

You can also use the > command to create an empty file:
    $ > tmp
    $ ls —s tmp
    0 tmp
This is equivalent to touch tmp.

Standard output can be appended to a file by using the >> redirect operator.

Standard output is closed with the >&- redirect operator:
    $ echo "This is going nowhere" >&-
    $


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值