本文介绍了到位变量的外壳替换字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我传递一个字符串作为参数传递给shell脚本。而shell脚本应该告诉我,如果传递的参数是一个变量
像这样
如果[! -z $ {$ 1}]。然后
回声是的! $ 1是一个变量,它的值是$ {$ 1}
科幻
但是这给了我不错的替代呃..
我肯定知道我失去了一些东西...帮助我!
例如用法:
$ HOME myscript.sh
是!家是一个变量,它的值是/ home /拉吉
解决方案
这个语法是:
$ {!VAR}
例如:
$函数你好(){回声$ {1}!; }
$ HOME打招呼
/家/我
I pass a string as an argument to a shell script. and the shell script should tell me if the passed argument is a variable
something like this
if [ ! -z ${$1} ] ; then
echo yes! $1 is a variable and its value is ${$1}
fi
but this gives me bad substitution err..
I definitely know i'm missing something.. help me out!
Eg usage:
$ myscript.sh HOME
yes! HOME is a variable and its value is /home/raj
解决方案
The syntax for this is:
${!VAR}
Example:
$ function hello() { echo ${!1}; }
$ hello HOME
/home/me
这篇关于到位变量的外壳替换字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!