原文链接:http://1985wanggang.blog.163.com/blog/static/776383320121745626320/


  1. a="one,two,three,four"

要将$a分割开,可以这样:


  1. OLD_IFS="$IFS"
  2. IFS=","
  3. arr=($a)
  4. IFS="$OLD_IFS"
  5. for s in ${arr[@]}
  6. do
  7. echo "$s"
  8. done

上述代码会输出


  1. one
  2. two
  3. three
  4. four

arr=($a)用于将字符串$a分割到数组$arr ${arr[0]} ${arr[1]} ... 分别存储分割后的数组第1 2 ... 项 ,${arr[@]}存储整个数组。变量$IFS存储着分隔符,这里我们将其设为逗号 "," OLD_IFS用于备份默认的分隔符,使用完后将之恢复默认。

Linux shell 将字符串分割成数组的更多相关文章

  1. [转+整理]linux shell 将字符串分割成数组

    原文链接:http://1985wanggang.blog.163.com/blog/static/776383320121745626320/ a="one,two,three,four& ...

  2. shell 将字符串分割成数组

    代码:test.sh #!/bin/bash a="one,two,three,four" #要将$a分割开,可以这样: OLD_IFS="$IFS" IFS= ...

  3. oracle根据分隔符将字符串分割成数组函数

    --创建表类型 create or replace type mytype as table of number;--如果定义成varchar--CREATE OR REPLACE type myty ...

  4. shell将字符串分隔成数组

    #!/bin/bash a="hello,world,nice,to,meet,you" #要将$a分割开,先存储旧的分隔符 OLD_IFS="$IFS" #设 ...

  5. 字符串---分割成数组(str_split ),算出一个字符串中出现最多的字符, 学校中最多的姓名

    split 分割separate分开 little 小的 echo '<meta http-equiv="Content-type" content="text/h ...

  6. php把字符串指定字符分割成数组

    <?php $str="1|2|3|4|5|"; $var=explode("|",$str); print_r($var); ?> $var=ex ...

  7. 随笔 JS 字符串 分割成字符串数组 并动态添加到指定ID的DOM 里

    JS /* * 字符串 分割成字符串数组 并动态添加到指定ID的DOM 里 * @id 要插入到DOM元素的ID * * 输入值为图片URL 字符串 * */ function addImages(i ...

  8. js 字符串分割成字符串数组 遍历数组插入指定DOM里 原生JS效果

    使用的TP3.2 JS字符串分割成字符串数组 var images='{$content.pictureurl} ' ;结构是这样 attachment/picture/uploadify/20141 ...

  9. split 将字符串分割成字符串数组

    list_name = list_name.split(","); split() 方法用于把一个字符串分割成字符串数组. 语法 stringObject.split(separa ...

随机推荐

  1. Java学习笔记22(List接口)

    List接口继承自Collection接口,自身具有三大特点: 1.有序集合:存入和取出的顺序一致: 2.此接口的用户可以对每个元素插入位置进行精确控制:可以通过索引操作元素 3.可以存储重复元素 L ...

  2. Python扩展库2—matplotlib

    1 载入matplotli的绘图模块,并重命名为plt import matplotlib.pyplot as plt 2 折线图 import matplotlib.pyplot as plt im ...

  3. java pojo类

    POJO POJO是Plain OrdinaryJava Object的缩写 可以当作简单的Java对象 实际就是普通JavaBeans 外文名 POJO 实际意义 普通JavaBeans 全     ...

  4. 【转载】 程序员制作996.icu网站抗议加班,你认为996能提高工作效率吗?

    原文地址: https://zhidao.baidu.com/question/623053193192988612.html ------------------------------------ ...

  5. batch normalization在测试时的问题

    验证: 在测试时可以一张图,但设置use_global_stats:true,已经验证,第一台4gpu上,路径:/home/guangcong/projects/unlabeled-video/tra ...

  6. 爬取贴吧中的html,并保存到相对应的文件夹中

    功能:输入要爬取的贴吧名称,起始页和终止页即可. # -*- coding: utf-8 -*- import urllib.request import urllib.parse import os ...

  7. 单调栈运用2----(xdoj-1156)

    #include <bits/stdc++.h> using namespace std; ; int num[N]; int len; int top; int t; deque < ...

  8. Django book manage system

    创建一个简易的可以增删改查book的书籍管理system urls.py from django.contrib import admin from django.urls import re_pat ...

  9. (3)HTML常用标签 + 快捷字符

    1.<meta charset="UTF-8">  #定义字符编码 2.<!doctype + 类型> #规定文档类型 3.<!-- 注释 --> ...

  10. gcd(1,n)+gcd(2,n)....gcd(n-1,n); Uva11426

    #include<bits/stdc++.h> #define int long long using namespace std; ; int phi[maxn]; int prime[ ...