参考资料: shell字符串分割再循环:http://www.shangxueba.com/jingyan/1633455.html linux shell中 if else以及大于.小于.等于逻辑表达式介绍:http://www.jb51.net/article/34332.htm Shell数组:shell数组的定义.数组长度:http://c.biancheng.net/cpp/view/7002.html shell 数组长度:http://blog.csdn.net/shaobingj
代码:test.sh #!/bin/bash a="one,two,three,four" #要将$a分割开,可以这样: OLD_IFS="$IFS" IFS="," arr=($a) IFS="$OLD_IFS" for s in ${arr[@]} do echo "$s" done shell编程中,经常需要将由特定分割符分割的字符串分割成数组,多数情况下我们首先会想到使用awk但是实际上用shell
1.截取 package java07; /* 字符串的截取方法: public String substring(int index):截取从参数位置一直到字符串末尾,返回新字符串 public String substring(int begin,int end);截取从begin开始,一直到end结束,中间的字符串.左闭右开 * */ public class DemoStringsub { public static void main(String[] args) { String s