Bash -x和sed问题 [英] Bash -x and sed problem

查看:82
本文介绍了Bash -x和sed问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从LibreOffice复制了以下内容并使用最佳猜测功能发布。希望格式化传递。





我使用以下函数输出bash -x调试脚本的当前行。 

echo_line_no(){
grep -n$ 1$ 0 | seds / echo_line_no //
#grep包含输入$ 1的行号,行号为
#replace函数名称,不带
}

I没有写功能,遗憾的是不记得来源。
当S1包含计划文本时,该功能有效,例如

echo_line_noSTART NEW_BuildCommand

当$ 1包含时,该功能无法正常工作变量因此bash -x调试选项仅在按顺序使用时输出第一个函数。


Bash脚本

choice =$ USERINPUT
4611 DynamicCommand =$ choice
4612
4613 echo_line_no 当前DynamicCommand
4614暂停
4615 echo_line_no当前DynamicCommand $ DynamicCommand
4616 echo_line_no当前DynamicCommand$ DynamicCommand
4617
4618暂停
4619 echo_line_noEND NEW_BuildCommand
4620暂停

bash输出-x

+ choice = lsusb
+ DynamicCommand = lsusb

输出显示通过echo_line_no函数按预期传递

+ echo_line_no'当前DynamicCommand'
+ sed s / echo_line_no //
+ grep -n'当前DynamicCommand'/ usr / bin / raspi-config-DEBUG.sh

按预期输出文本和行号

4613:当前DynamicCommand

未能输出通过echo_line_no函数传递,
不输出变量

4615:当前DynamicCommand $ DynamicCommand
4616:当前DynamicCommand$ Dynami c命令
+暂停





我尝试过:



我不明白为什么功能失败,所以我没猜到解决方法/解决方案。

但是我确实为变量尝试了不同的语法。

解决方案

1


0 | seds / echo_line_no //
#grep包含输入的行


1,行号为
#replace函数名,不带
}

我没有写这个函数,遗憾的是不记得来源。
当S1包含计划文本时,该功能有效,例如

echo_line_noSTART NEW_BuildCommand


I have copied the following from LibreOffice and used "best guess" feature to post it. Hope the formatting pass.


I am using the following function to output current line of bash -x debug script.

echo_line_no () {
	grep -n "$1" $0 |  sed "s/echo_line_no//"
           # grep the line(s) containing input $1 with line numbers
     	#replace the function name with nothing
  	} 

I did not write the function and unfortunately do not recall the source. 
The function works when "S1" contains plan text, such as 

echo_line_no "START NEW_BuildCommand"

The function does not work as expected when "$1" contains "variables " consequently  bash -x debug option outputs only first pass to the function when used in sequence. 


Bash script 

choice="$USERINPUT" 
4611 DynamicCommand="$choice"
4612
4613 echo_line_no "Current DynamicCommand"
4614 pause 
4615 echo_line_no "Current DynamicCommand $DynamicCommand"
4616 echo_line_no "Current DynamicCommand "$DynamicCommand" "
4617
4618 pause 
4619 echo_line_no "END NEW_BuildCommand"
4620 pause 

Output from bash -x 

+ choice=lsusb
+ DynamicCommand=lsusb

outputs shows pass thru echo_line_no function as expected 

+ echo_line_no 'Current DynamicCommand'
+ sed s/echo_line_no//
+ grep -n 'Current DynamicCommand' /usr/bin/raspi-config-DEBUG.sh

outputs text and line number as expected 

4613: "Current DynamicCommand"

fails to  output pass thru echo_line_no function and 
does not output variable  

4615: "Current DynamicCommand $DynamicCommand"
4616: "Current DynamicCommand "$DynamicCommand" "
+ pause



What I have tried:

I do not understand WHY the function is failing, so I did not guess the workaround / solution.
But I did try different syntax for variable.

解决方案

1"


0 | sed "s/echo_line_no//" # grep the line(s) containing input


1 with line numbers #replace the function name with nothing } I did not write the function and unfortunately do not recall the source. The function works when "S1" contains plan text, such as echo_line_no "START NEW_BuildCommand" The function does not work as expected when "


这篇关于Bash -x和sed问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆