shell脚本使用技巧5--字符分隔
#!/bin/bash
#filename:ifs.sh
data="name,sex,rollon,location"
oldIFS=$IFS
IFS=,
for item in $data;
do
echo Item: $item
done #IFS=$oldIFS
设置IFS为,号分隔符
#!/bin/bash
#filename:fenge.sh
line="root:x:0:0:root:/root:bin/bash"
oldIFS=$IFS
IFS=":"
count=
for item in $line;
do
[ $count -eq ] && user=$item;
[ $count -eq ] && shell=$item;
let count++
done;
IFS=$oldIFS
echo $user\'s shell is $shell;
注意:[ ]空格;
shell脚本使用技巧5--字符分隔的更多相关文章
- shell脚本常用技巧
shell脚本常用技巧 1.获取随机字符串或数字 ~]#echo $RANDOM | md5sum | cut -c 1-6 ~]#openssl rand -base64 4 | cut -c 1- ...
- shell脚本使用技巧3--调试
1.使用-x,开启shell脚本的跟踪调试功能 ex:bash -x script.sh or sh -x script.sh 2.使用set -x 和 set +x对脚本进行部分调试(输入中间的内容 ...
- shell脚本调试技巧
shell脚本调试之工具——bashdb http://www.cnblogs.com/itcomputer/p/5011845.html
- shell脚本使用技巧4--读取字符,重复执行
ls | cat -n > out.txt 给输出的信息加行号并导出到out.txt 利用shell生成一个独立的进程 pwd; (cd /bin; ls); pwd; 开启一个子shell,不 ...
- shell脚本常规技巧
邮件相关 发送邮件: #!/usr/bin/python import sys; import smtplib; from email.MIMEText import MIMEText mail_ho ...
- SHELL 脚本小技巧
脚本很简单,直接上功能介绍及脚本,可以做模板使用: 记录日志,记录脚本开始执行时间.结束时间 usage 函数,脚本需接参数执行,避免误执行,告诉用户,这个脚本的使用方法 加锁,创建锁文件,脚本不允许 ...
- shell脚本小技巧
输入参数错误时,退格会出现^H,这个时候只要在脚本顶部加一条语句:stty erase ^h就可以了 #!/bin/sh stty erase ^h
- Shell脚本小技巧收集
1.使用python快速搭建一个web服务器 访问端口8000 python -m SimpleHTTPServer 2.获取文件大小 stat -c %s $file stat --printf=' ...
- shell脚本使用技巧2
0--stdin标准输入 1--stdout标准输出 2--stderr标准错误 重定向 echo "this is a good idea " > temp.txt tem ...
随机推荐
- config.GetSection(key)编译不通过
要安装这个版本
- Redis cluster集群模式的原理
redis cluster redis cluster是Redis的分布式解决方案,在3.0版本推出后有效地解决了redis分布式方面的需求 自动将数据进行分片,每个master上放一部分数据 提供内 ...
- Top 查看某些或者某个进程(top -p pid)
https://blog.csdn.net/zhangfn2011/article/details/7488746?utm_source=blogxgwz5
- ubuntu下的“用vim打开中文乱码,用cat打开正常显示”的解决方法
转载 系统环境:ubuntu10.04 vim gvim完全安装 问题:终端下vim中的汉字为乱码,网上搜索了一些解决方案.但是奇怪的是,这些方法都不能实现gvim的菜单和文中汉字,终端vim下的文中 ...
- [转]10 Awesome Indicator Applets for Ubuntu’s Unity Desktop
http://blogger.gtwang.org/2013/10/awesome-indicator-applets-for-ubuntus-unity-desktop.html http://ww ...
- ElementLayer support not implemented for native rendering. Layer ID:
在 arcgis runtime for wpf 添加标注闪烁动画时(实现方法参考:http://blog.csdn.net/arcgisserver_book/article/details/805 ...
- SpringBoot Controller接收参数的几种常用方
第一类:请求路径参数 1.@PathVariable 获取路径参数.即url/{id}这种形式. 2.@RequestParam 获取查询参数.即url?name=这种形式 例子 GET http:/ ...
- PHP页面间传值的几种方法
方法一:require_once //Page a: <?php $a = "hello"; ?> //Page b: <?php require_once &q ...
- BZOJ2527 [Poi2011]Meteors 整体二分 树状数组
原文链接http://www.cnblogs.com/zhouzhendong/p/8686460.html 题目传送门 - BZOJ2527 题意 有$n$个国家. 太空里有$m$个太空站排成一个圆 ...
- IISExpress运行网站时,Service Fabric报Could not load file or assembly 'Microsoft.ServiceFabric.Data' or one of its dependencies. An attempt was made to load a program with an incorrect format.
打开VS TOOLS > OPTIONS > Projects and Solutions > WEB PROJECTS,选中 "Use the 64 bit vers ...