ifs

How does splitting string to array by 'read' with IFS word separator in bash generated extra space element?

一世执手 提交于 2019-12-13 15:51:08
问题 With only one character for IFS, it works fine: shell@kernel: ~> l="2.4.3"; IFS="." read -a la <<< "$l"; for ((i = 0; i < ${#la[@]}; ++i)) do echo ${la[$i]}; done; 2 4 3 While there are two characters for IFS, extra space element generated shell@kernel: ~> l="2->4->3"; IFS="->" read -a la <<< "$l"; for ((i = 0; i < ${#la[@]}; ++i)) do echo ${la[$i]}; done; 2 4 3 shell@kernel: ~> l="2..4..3"; IFS=".." read -a la <<< "$l"; for ((i = 0; i < ${#la[@]}; ++i)) do echo ${la[$i]}; done; 2 4 3 How can

How does IFS work in Bash?

萝らか妹 提交于 2019-12-11 09:17:21
问题 #!/bin/bash # This question is from advanced bash scripting guide section 5.1 echo var="'(]\\{}\$\"" IFS='\' echo $var # output is '(] {}$" # \ converted to space. Why? echo "$var" # output is '(]\{}$" # special meaning of \ used, \ escapes \ $ and " RIGHT? echo var2="\\\\\"" echo $var2 # output is " # \ converted to space. Why? echo # But ... var2="\\\\"" is illegal. Why? var3='\\\\' echo "$var3" # \\\\ # Strong quoting works, though. Why? 回答1: IFS='\' echo $var # o/p is '(] {}$" # \

linux(macbook)实际工作笔录

。_饼干妹妹 提交于 2019-12-09 15:20:35
批量拷贝某一个目录下的所有指定的文件到另一个指定的目录 ## 比如拷贝视频文件,针对目录下存在空格命名情况,会导致无法处理成功,需要临时使用系统变量的IFS #!/bin/bash old_IFS = $IFS IFS = $( echo -en "\n\b" ) find . -name "*.mp4" | while read filepath do echo "move file to 100036 dir: $filepath " mv -f $filepath ./100036 done # 恢复系统原理的设置 IFS = $old_IFS 基于云端的API服务进行批量处理 ### 比如github上批量删除无效仓库项目 # 在本地新建一个文件repos,逐行贴上对应的一个仓库名称: githubName/repoName,如: xiaokunliu/delRepo1 xiaokunliu/delRepo2 .. . # github上申请对应开发者账户的删除权限token ### 编写脚本完成 #!/bin/bash cat repos | while read repo do echo "delete github for repo: https://api.github.com/repos/ $repo " curl -XDELETE -H

IFS change with Bash 4.2

 ̄綄美尐妖づ 提交于 2019-12-09 02:05:23
问题 Running these commands gives expected results $ bash --version GNU bash, version 4.1.11(2)-release $ foo=(111 222 333) $ IFS=, cat <<< "${foo[*]}" 111,222,333 However it appears with Bash 4.2 the IFS value is being ignored $ bash --version GNU bash, version 4.2.0(1)-release $ foo=(111 222 333) $ IFS=, cat <<< "${foo[*]}" 111 222 333 What is causing this difference? I found the answer here http://lists.gnu.org/archive/html/bug-bash/2014-03/msg00065.html It looks as though this has been an

C: IFS System() Vulnerability

99封情书 提交于 2019-12-07 06:43:07
问题 For educational reasons I have to exploit an C-Code The Programm set the egid first, and then the vulnerability with the system("/usr/bin/..."); Command. So I made an 'usr' executeable in my Home-Directory and set the Path to the Home PATH=$HOME:$PATH And I want to change the IFS Variable in the bash to /: export IFS='/' Unfortunatelly, when i call the C-Programm: my exploit doesn't work Is anybody able to tell me what is wrong? 回答1: I suppose we are studying at the same university, because I

Linux:IFS分隔符的使用

老子叫甜甜 提交于 2019-12-06 21:41:19
IFS分隔符的使用 data="name, gender,rollno,location" 我们可以使用IFS读取变量中的每一个条目。 oldIFS=$IFS IFS=, #IFS现在被设置为, for item in $data; do echo Item: $item done IFS=$oldIFS 输出如下: Item: name Item: gender Item: rollno Item: location IFS的默认值为空白字符(换行符、制表符或者空格)。 当IFS被设置为逗号时,shell将逗号视为一个定界符,因此变量 $item 在每次迭代中读取由逗号分隔的子串作为变量值。 来源: https://www.cnblogs.com/moox/p/11997832.html

python 抓包与解包

北战南征 提交于 2019-12-06 16:59:19
我使用的环境为:Windows10、python3.6、scapy 2.4.0 一、基本知识 Sniff方法定义: sniff(filter= "" ,iface= "any" , prn=function, count=N) filter的规则使用 Berkeley Packet Filter (BPF)语法 iface用来指定要在哪个网络接口上进行抓包(通常不指定即所有网络接口) prn指定回调函数,每当一个符合filter的报文被探测到时,就会执行回调函数,通常使用 lambda 表达式来写回调函数 count指定最多嗅探多少个报文(是指符合filter条件的报文,而非所有报文) filter写法举例: 抓取源地址为 www.baidu.com 的报文: >>> sniff(filter= "ip src www.baidu.com" , iface=ifs, prn= lambda x:x.summary(), count= 3 ) Ether / IP / TCP 14.215 .177 .39 :https > 192.168 .2 .204 : 6593 A / Padding Ether / IP / TCP 14.215 .177 .39 :https > 192.168 .2 .204 : 6593 A / Padding Ether / IP / TCP 14

Split string using \r\n using IFS in bash

南笙酒味 提交于 2019-12-06 13:44:54
问题 I would like to split string contains \r\n in bash but carriage return and \n gives issue. Can anyone give me hint for different IFS? I tried IFS=' |\' too. input: projects.google.tests.inbox.document_01\r\nprojects.google.tests.inbox.document_02\r\nprojects.google.tests.inbox.global_02 Code: IFS=$'\r' inputData="projects.google.tests.inbox.document_01\r\nprojects.google.tests.inbox.document_02\r\nprojects.google.tests.inbox.global_02" for line1 in ${inputData}; do line2=`echo "${line1}"`

C: IFS System() Vulnerability

懵懂的女人 提交于 2019-12-05 10:50:00
For educational reasons I have to exploit an C-Code The Programm set the egid first, and then the vulnerability with the system("/usr/bin/..."); Command. So I made an 'usr' executeable in my Home-Directory and set the Path to the Home PATH=$HOME:$PATH And I want to change the IFS Variable in the bash to /: export IFS='/' Unfortunatelly, when i call the C-Programm: my exploit doesn't work Is anybody able to tell me what is wrong? I suppose we are studying at the same university, because I am currently confronted with the same problem. I don't want to give you the whole solution, because that

Setting IFS for a single statement

我只是一个虾纸丫 提交于 2019-12-04 08:54:52
On my GNU bash, version 4.3.42(1)-release I am doing some tests to answer a question . The idea is to split a : -separated string and and each of its elements into an array. For this, I try to set the IFS to : in the scope of the command, so that the split is automatic and IFS remains untouched: $ myvar="a:b:c" $ IFS=: d=($myvar) $ printf "%s\n" ${d[@]} a b c And apparently IFS remains the same: $ echo $IFS # empty The BASH reference says that: If IFS is unset, the parameters are separated by spaces. If IFS is null, the parameters are joined without intervening separators. However, then I