Linux command’s Array

#数组的声明与遍历
animals=("a dog" "a cat" "a fish")
#wrong ways to use this
for i in ${animals[*]}; do echo $i; done
for i in ${animals[@]}; do echo $i; done
for i in "${animals[*]}"; do echo $i; done

#this is what we want correct way to use
for i in "${animals[@]}"; do echo $i; done

#数组元素的排序
a=(f e d c b a)
echo "Original array: ${a[@]}"
a_sorted=($(for i in "${a[@]}"; do echo $i; done | sort))
echo "Sorted array: ${a_sorted[@]}"

#删除数组长或数组的某个元素
foo=(a b c d e f)
echo ${foo[@]}
unset foo[2]
echo ${foo[@]}

cut 命令从文件的每一行剪切字节、字符和字段并将这些字节、字符和字段写至标准输出。
主要参数
-b :以字节为单位进行分割。这些字节位置将忽略多字节字符边界,除非也指定了 -n 标志。
-c :以字符为单位进行分割。
-d :自定义分隔符,默认为制表符。
-f  :与-d一起使用,指定显示哪个区域。
-n :取消分割多字节字符。仅和 -b 标志一起使用。如果字符的最后一个字节落在由 -b 标志的 List 参数指示的<br />范围之内,该字符将被写出;否则,该字符将被排除。
#split string to array one demo
foo="hello world hello java hello docker hello spark hello stream"
declare -a bar
read -a bar <<<$foo

时间: 2024-12-22 08:54:54

Linux command’s Array的相关文章

10 Interesting Linux Command Line Tricks and Tips Worth Knowing

I passionately enjoy working with commands as they offer more control over a Linux system than GUIs(Graphical User Interfaces) applications, therefore am always on the look out to discover or figure out interesting ways and ideas to make Linux so eas

[Linux Command Line and Shell Scripting Bible] basic shell script

1 #!/bin/bash 2 ############################################ 3 # @content chapter 8,9 of Linux Command Line and Shell Scripting Bible 4 # @reader gavin 5 # @date 2014/12/14 6 ############################################ 7 CHAPTER 8 8 9 + user varriab

[Linux/Command] wc

wc 命令可以打印目标文件的换行.单词和字节数.其中换行数 = 总行数 - 1,单词数则按照空格分隔的英文单词数进行统计,也就是说连续的汉字(短语.句子)都视作一个单词. NAME wc - 打印每个目标文件的换行.单词和字节数量. SYNOPSIS wc [OPTION]... [FILE]... wc [OPTION]... --files0-from=F DESCRIPTION 打印每个目标文件的换行.单词和字节数量,如果给定多个目标文件,则同时打印汇总数量. 如果不给定目标文件,或者给定

Linux command automake

Linux command automake [Purpose]        Learning linux command automake for generate Makefile.in for configure from Makefile.am   [Eevironment]        Ubuntu 16.04 terminal   [Procdeure]        example: 如何安装: sudo apt-get autoremove automake sudo apt

Linux command stty

Linux command stty reference: https://blog.csdn.net/lqxandroid2012/article/details/78929506 [Purpose]        Learning linux command stty for get/set serial uart speed    [Eevironment]        Ubuntu 16.04 terminal   [Procdeure]        example get uart

linux command lynx

[Purpose]        Learning linux command  lynx   [Eevironment]        Ubuntu 16.04 terminal   apt-get install lynx usage assic to strage web content example: [email protected]:/media/vmuer/share# lynx -dump http://www.ruanyifeng.com/blog/2018/12/git-b

Linux Command Backup

User Structure linux command review 列出所有信号 找到名字后,kill 或者用ps找到 kill同名进程 每隔一秒高亮显示网络链接数的变化情况 启动关闭制定网卡 关闭网卡并修改MAC地址 配置IP地址 显示当前路由器 添加网关 删除网关 下载到本地 显示TCP连接 socket 摘要 列出所有打开的网络连接端口 显示所有UDP Sockets User create an account useradd shanshan delete an account u

Linux Command Line 笔记(1)

Yunduan CUI graphical user interfaces make easy tasks easy, while command line interfaces make difficult tasks possible Part 1 学习Shell 1. 什么是 Shell? Shell 是用户与操作系统交流的程序,它读取用户的键盘输入并交由操作系统执行相应的命令.所有linux都支持一个叫做 bash 的shell,它的全称是 "Bourne Again SHell&quo

the linux command line学习笔记之三

linux键盘操作技巧 光标移动: Ctrl-a    Move cursor to the beginning of the line.Ctrl-e    Move cursor to the end of the line.Ctrl-f     Move cursor forward one character; same as the right arrow key.Ctrl-b    Move cursor backward one character; same as the left