小编Dan*_*ela的帖子

Bash:从特定行开始运行脚本

我有办法从特定的行开始运行bash脚本吗?

假设我的脚本看起来像这样:

0 #!/bin/bash
1 ...
2 clone a repository
3 ...
4 command that crashed
Run Code Online (Sandbox Code Playgroud)

我去修复第4行,我想重新运行脚本而不运行第1,2,3行的代码,而是直接从第4行开始.

我快速搜索这个问题的标题没有给我答案.如果有办法用bash做到这一点,那将是有用的.

谢谢你的答案.如果你还想在开头保留一些行,另一个解决方案是:

 # assuming you want to run your script except from line 4 to 7
 sed '4,7s/^/#/g' -i script.sh; ./sript.sh #this replaces the beginning of the line ^ with # from lines 4 to 7
 # to undo the comments
 sed '4,7s/^#//g' -i script.sh; ./sript.sh
Run Code Online (Sandbox Code Playgroud)

bash

3
推荐指数
1
解决办法
3418
查看次数

标签 统计

bash ×1