首页 > 其他分享 >IFS分隔符的使用

IFS分隔符的使用

时间:2024-03-02 11:00:43浏览次数:13  
标签:064143 od 051506 使用 IFS 044444 062412 020157 分隔符

 

替换换行符

IFS 和echo一起配合才有作用

#!/bin/bash

echo $IFS|od -b
old_if=$IFS
IFS=$'\n'
echo `lsmod|awk '{print $1}'`
IFS=$old_if
echo $IFS|od -b

  结果

0000000 012
0000001
Module binfmt_misc xt_LOG nf_log_syslog xt_set ip6t_rpfilter ip6table_nat ip6table_mangle ip6table_security ip6table_raw ip6t_REJECT nf_reject_ipv6 ip6table_filter ip6_tables iptable_nat nf_nat iptable_mangle iptable_security iptable_raw ipt_REJECT nf_reject_ipv4 xt_conntrack nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 iptable_filter ip_tables ebtable_nat ebtable_broute ebtable_filter ebtables ip_set_hash_ip udp_diag tcp_diag inet_diag libcrc32c rfkill ip_set nfnetlink intel_rapl_common intel_uncore_frequency_common isst_if_mbox_msr isst_if_common nfit crct10dif_pclmul crc32_pclmul polyval_clmulni polyval_generic ghash_clmulni_intel sha512_ssse3 sha256_ssse3 sha1_ssse3 aesni_intel crypto_simd cryptd rapl joydev input_leds pcspkr virtio_balloon floppy qemu_fw_cfg i2c_piix4 tcp_bbr sch_fq ext4 mbcache jbd2 virtio_net net_failover virtio_blk virtio_console failover ata_generic pata_acpi crc32c_intel ata_piix cirrus drm_shmem_helper drm_kms_helper serio_raw virtio_pci virtio virtio_pci_legacy_dev virtio_pci_modern_dev virtio_ring drm libata
0000000 

  

od命令

命令用于转换不同格式的输入内容,以八进制格式为默认格式。在调试 Linux 脚本中是否存在不需要的更改或字符时,此命令特别有用。如果指定了多个文件,od 命令将按列出的顺序将它们连接起来形成输入。它可以以多种其他格式显示输出,包括十六进制、十进制和 ASCII。它对于可视化非人类可读格式的数据非常有用,例如程序的可执行代码。句法

 -b 选项:以八进制格式显示输入的内容
[root@hcss-ecs-c16f ~]# od -b 5.sh
0000000 043 041 057 142 151 156 057 142 141 163 150 012 012 145 143 150
0000020 157 040 044 111 106 123 174 157 144 040 055 142 012 157 154 144
0000040 137 151 146 075 044 111 106 123 012 111 106 123 075 044 047 134
0000060 156 047 012 145 143 150 157 040 140 154 163 155 157 144 174 141
0000100 167 153 040 047 173 160 162 151 156 164 040 044 061 175 047 140
0000120 012 111 106 123 075 044 157 154 144 137 151 146 012 145 143 150
0000140 157 040 044 111 106 123 174 157 144 040 055 142 012
0000155
[root@hcss-ecs-c16f ~]# cat 5.sh
#!/bin/bash

echo $IFS|od -b
old_if=$IFS
IFS=$'\n'
echo `lsmod|awk '{print $1}'`
IFS=$old_if
echo $IFS|od -b

 -c 选项:以字符格式显示输入的内容。

[root@hcss-ecs-c16f ~]# od -c 5.sh
0000000   #   !   /   b   i   n   /   b   a   s   h  \n  \n   e   c   h
0000020   o       $   I   F   S   |   o   d       -   b  \n   o   l   d
0000040   _   i   f   =   $   I   F   S  \n   I   F   S   =   $   '   \
0000060   n   '  \n   e   c   h   o       `   l   s   m   o   d   |   a
0000100   w   k       '   {   p   r   i   n   t       $   1   }   '   `
0000120  \n   I   F   S   =   $   o   l   d   _   i   f  \n   e   c   h
0000140   o       $   I   F   S   |   o   d       -   b  \n
0000155

-An 它以字符格式显示输入的内容,但没有偏移量信息

od -An -c 5.sh
   #   !   /   b   i   n   /   b   a   s   h  \n  \n   e   c   h
   o       $   I   F   S   |   o   d       -   b  \n   o   l   d
   _   i   f   =   $   I   F   S  \n   I   F   S   =   $   '   \
   n   '  \n   e   c   h   o       `   l   s   m   o   d   |   a
   w   k       '   {   p   r   i   n   t       $   1   }   '   `
  \n   I   F   S   =   $   o   l   d   _   i   f  \n   e   c   h
   o       $   I   F   S   |   o   d       -   b  \n
You have new mail in /var/spool/mail/root

-A选项:通过连接一些特殊字符以不同的格式显示输入的内容

1. -Ax 表示十六进制格式(我们将 x 与 -A 连接)

2. -Ao 表示十六进制格式(我们将 o 与 -A 连接)

3. -Ad 表示十六进制格式(我们将 d 与 -A 连接) 语法:

[root@hcss-ecs-c16f ~]# od -Ax 5.sh
000000 020443 061057 067151 061057 071541 005150 062412 064143
000010 020157 044444 051506 067574 020144 061055 067412 062154
000020 064537 036546 044444 051506 044412 051506 022075 056047
000030 023556 062412 064143 020157 066140 066563 062157 060574
000040 065567 023440 070173 064562 072156 022040 076461 060047
000050 044412 051506 022075 066157 057544 063151 062412 064143
000060 020157 044444 051506 067574 020144 061055 000012
00006d
[root@hcss-ecs-c16f ~]# od -Ao 5.sh
0000000 020443 061057 067151 061057 071541 005150 062412 064143
0000020 020157 044444 051506 067574 020144 061055 067412 062154
0000040 064537 036546 044444 051506 044412 051506 022075 056047
0000060 023556 062412 064143 020157 066140 066563 062157 060574
0000100 065567 023440 070173 064562 072156 022040 076461 060047
0000120 044412 051506 022075 066157 057544 063151 062412 064143
0000140 020157 044444 051506 067574 020144 061055 000012
0000155
[root@hcss-ecs-c16f ~]# od -Ad 5.sh
0000000 020443 061057 067151 061057 071541 005150 062412 064143
0000016 020157 044444 051506 067574 020144 061055 067412 062154
0000032 064537 036546 044444 051506 044412 051506 022075 056047
0000048 023556 062412 064143 020157 066140 066563 062157 060574
0000064 065567 023440 070173 064562 072156 022040 076461 060047
0000080 044412 051506 022075 066157 057544 063151 062412 064143
0000096 020157 044444 051506 067574 020144 061055 000012
0000109

-   接受来自命令行的输入,输入3行返回一个结果

[root@hcss-ecs-c16f ~]# od -c -
s
sdfafsdf
sadf
0000000   s  \n   s   d   f   a   f   s   d   f  \n   s   a   d   f  \n
1111111
222
111
0000020   1   1   1   1   1   1   1  \n   2   2   2  \n   1   1   1  \n

 

-j  它在跳过一些字节后显示输出

[root@hcss-ecs-c16f ~]# od -j4 -c 5.sh
0000004   i   n   /   b   a   s   h  \n  \n   e   c   h   o       $   I
0000024   F   S   |   o   d       -   b  \n   o   l   d   _   i   f   =
0000044   $   I   F   S  \n   I   F   S   =   $   '   \   n   '  \n   e
0000064   c   h   o       `   l   s   m   o   d   |   a   w   k       '
0000104   {   p   r   i   n   t       $   1   }   '   `  \n   I   F   S
0000124   =   $   o   l   d   _   i   f  \n   e   c   h   o       $   I
0000144   F   S   |   o   d       -   b  \n
0000155
[root@hcss-ecs-c16f ~]# od -j4 5.sh
0000004 067151 061057 071541 005150 062412 064143 020157 044444
0000024 051506 067574 020144 061055 067412 062154 064537 036546
0000044 044444 051506 044412 051506 022075 056047 023556 062412
0000064 064143 020157 066140 066563 062157 060574 065567 023440
0000104 070173 064562 072156 022040 076461 060047 044412 051506
0000124 022075 066157 057544 063151 062412 064143 020157 044444
0000144 051506 067574 020144 061055 000012

  

资料 https://www.geeksforgeeks.org/od-command-linux-example/        

标签:064143,od,051506,使用,IFS,044444,062412,020157,分隔符
From: https://www.cnblogs.com/lzjloveit/p/18048393

相关文章

  • 笔记:Git学习之应用场景和使用经验
    目标:整理Git工具的应用场景和使用经验一、开发环境Git是代码版本控制工具;Github是代码托管平台。工具组合:VSCode+Git需要安装的软件:vscode、Git其中vscode需要安装的插件:GitLens、GitHistory二、应用场景工作场景:嵌入式开发,多人本地使用三、使用总结基础操作,参考廖雪峰的Git教......
  • C++类开发的第六篇(虚拟继承实现原理和cl命令的使用的bug修复)
    Class_memory接上一篇末尾虚拟继承的简单介绍之后,这篇来详细讲一下这个内存大小是怎么分配的。使用clcl是MicrosoftVisualStudio中的C/C++编译器命令。通过在命令行中键入cl命令,可以调用VisualStudio的编译器进行编译操作。cl命令提供了各种选项和参数,用于指定源......
  • STM32OLED使用
    STM32OLED使用.mdSTM32OLED使用市面上大部分OLED使用SSD1306作为主控芯片,在这里使用STM32F103作为主控芯片,使用IIC总线点亮OLED。1.IIC设置以及初始化共需要引用4个头文件“stm32f10x_rcc.h”,“stm32f10x_gpio.h”,“stm32f10x_i2c.h”,“string.h”voidIIC_init(){RCC_A......
  • 自定义 DataLoader 时应使用 Unix 系统
    自定义Dataset类PyTorch允许自定义Dataset类,并由此获得DataLoader,能方便训练时获得batch:fromtorch.utils.dataimportDataLoader,Datasetimporth5pyimportosclassRadarDataset(Dataset):def__init__(self,directory):...def__len__(s......
  • STM32硬件IIC使用
    STM32硬件IIC使用.md概述虽然STM32的硬件IIC据说有设计缺陷,但是经过我的实践,至少STM32F103的硬件IIC是没问题的。这里给出STM32的硬件IIC的使用以及编程思路。1.STM32硬件IIC引脚在这里给出STM32F103的硬件IIC引脚,方便查阅使用2.STM32硬件IIC使用流程STM32的硬件IIC我认......
  • 【Azure Logic App】在中国区的微软云服务上,使用逻辑应用是否可以下载SharePoint上的
    问题描述在中国区的微软云服务上,使用逻辑应用是否可以下载SharePoint上的文件呢?目前遇见的问题时,选择LogicApp的SharePoint组件,登录SharePoint账号时,只能选择中国区的登录账号,不能使用GlobalSharepoint账号。问题解答AzureChina的LogicApp中的SharepointConnector只能......
  • 在 Spring Boot 3.x 中使用 SpringDoc 2 / Swagger V3
    SpringDocV1只支持到SpringBoot2.xspringdoc-openapiv1.7.0isthelatestOpenSourcereleasesupportingSpringBoot2.xand1.x.SpringBoot3.x要用SpringDoc2/SwaggerV3,并且包名也改成了springdoc-openapi-starter-webmvc-uiSpringDocV2https://spr......
  • 使用-solidity-开发第一个-以太坊智能合约
    目录目录使用solidity开发第一个以太坊智能合约前言项目源代码最终效果环境搭建智能合约内容Truffle创建项目Truffle编码Truffle打包Truffle部署修改编译器版本0.8.19Truffle测试创建测试文件运行测试命令Dapp命令总结遇到的问题注意Solidity......
  • Ubuntu中安装使用QEMU/KVM/virt-manager运行虚拟机
    本文为原创,原文发布于个人博客网站:Ubuntu中安装使用QEMU/KVM/virt-manager运行虚拟机有时候我们需要在同一台计算机中使用多种不同操作系统环境,基于已有的同一堆硬件资源来获得不同操作系统各自的便利性。对此,常用的解决方案主要有:在物理机器中安装使用双系统在宿主系统中安......
  • 使用 chrome 的本地 Mock 功能
    1.前言   过去,本地调试要用mock的话,需要我们可以通过代理的方式去hack的实现或者使用其它的工具实现,但是现在再也不用这么麻烦了,chrome原生就支持了,而且体验相当丝滑 2.使用方法  如果你的chrome浏览器没有以下功能,则需要更新到最新的版本第一步:找到需要mock的......