Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1741750
  • 博文数量: 297
  • 博客积分: 285
  • 博客等级: 二等列兵
  • 技术积分: 3006
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-06 22:04
个人简介

Linuxer, ex IBMer. GNU https://hmchzb19.github.io/

文章分类

全部博文(297)

文章存档

2020年(11)

2019年(15)

2018年(43)

2017年(79)

2016年(79)

2015年(58)

2014年(1)

2013年(8)

2012年(3)

分类: LINUX

2016-04-17 20:15:20

shopt -s -o nounset: 开启变量检查,如果一个使用的变量没有值,则会报错。unbound variable
<<'HERE' : 这样的用法,则所有的内容都会被认为是纯文本。
<<-EOF   : 则默认会在每行前面加上indent.
但是很奇怪的是,在here document里面的echo -e good\t也无法正常的输出了。输出是goodt, \t没有被解释为tab.

点击(此处)折叠或打开

  1. shopt -s -o nounset

  2. Script="$( cat <<'HERE'
  3. hostname;
  4. cat /etc/issue;
  5. id root
  6. HERE
  7. )"

  8. cat <<-HERE>command.hist
  9. #cat <<-'HERE'>command.hist
  10. echo $SHELL
  11. `hostname`;
  12. `cat /etc/issue`;
  13. id root
  14. `echo -e good\t`
  15. HERE

  16. root=`id`
  17. echo $root

  18. #ssh -t root@192.168.0.102 ${Script}

我本来想用here document 生成文件里面含有tab,或者空格,但是感觉还是不方便。
还是只能用echo 或者printf 实现。

点击(此处)折叠或打开

  1. echo -e "email\tlast\tfirst
  2. kobe@example.com\tkobe\the
  3. jason@example.com\x09jason\011kid" >tab_delim.txt
  4. printf "email\tlast\tfirst
  5. kobe@example.com\tkobe\the
  6. jason@example.com\x09jason\011kid" > tab_delim.txt
  7. #\x09 或者\011 \t 都是tab
查看文件的不可打印字符:

点击(此处)折叠或打开

  1. cat -A tab_delim.txt
  2. vim: set list      
  3. vim: set nolist
  4. vim: digraph #查看可以输入的特殊字符
最后介绍下shopt的几个用法:shopt 是bash的builtin.

点击(此处)折叠或打开

  1. man builtin     #可以寻找shopt
  2. shopt -p #查看当前设置
  3. shopt -o 
  4. shopt -s #enable a set
  5. shopt -u #disable a set

  6.        shopt [-pqsu] [-o] [optname ...]
  7.               Toggle the values of settings controlling optional shell behavior. The settings can be either those listed below, or, if the -o option is used, those available with the -o option to the set builtin com‐
  8.               mand. With no options, or with the -p option, a list of all settable options is displayed, with an indication of whether or not each is set. The -p option causes output to be displayed in a form that
  9.               may be reused as input. Other options have the following meanings:
  10.               -s Enable (set) each optname.
  11.               -u Disable (unset) each optname.
  12.               -q Suppresses normal output (quiet mode); the return status indicates whether the optname is set or unset. If multiple optname arguments are given with -q, the return status is zero if all optnames
  13.                      are enabled; non-zero otherwise.
  14.               -o Restricts the values of optname to be those defined for the -o option to the set builtin.




阅读(1230) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~