提取shell脚本中的所有变量值 [英] Extract all variable values in a shell script

查看:65
本文介绍了提取shell脚本中的所有变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调试一个旧的shell脚本;我想检查所有使用的变量的值,这是一个庞大的丑陋脚本,使用了大约140多个变量.无论如何,我可以从脚本中提取变量名称,并将其放在方便的模式下,例如:

I'm debugging an old shell script; I want to check the values of all the variables used, it's a huge ugly script with approx more than 140 variables used. Is there anyway I can extract the variable names from the script and put them in a convenient pattern like:

#!/bin/sh
if [ ${BLAH} ....
.....
rm -rf ${JUNK}.....

echo ${BLAH}
echo ${JUNK}
...

推荐答案

您可以使用以下命令在一个命令中转储所有感兴趣的变量:

You can dump all interested variables in one command using:

set | grep -w -e BLAH -e JUNK

要将所有变量转储到stdout,请使用:

To dump all the variables to stdout use:

set

env

从脚本内部.

这篇关于提取shell脚本中的所有变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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