prevent *在bash脚本扩展 [英] Prevent * to be expanded in the bash script

查看:77
本文介绍了prevent *在bash脚本扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Linux的bash脚本:

Linux bash script:

#!/bin/bash

function Print()
{
    echo $1
}

var="*"
Print $var

执行结果:

alex@alex-linux:~/tmp$ ./sample-script 
sample-script

* 扩展到文件列表,这实际上是脚本本身。我如何prevent这一点,看看实际的变量值?在一般的情况下, VAR 可以比 * ,例如更复杂的:

* is expanded to the list of files, which is actually script itself. How can I prevent this and see actual variable value? In general case, var can be more complicated than *, for example: home/alex/mydir/*.

推荐答案

你需要逃避你的变量,也:

you need to escape your variables, too:

Print "$var"

而在你的功能:

echo "$1"

这篇关于prevent *在bash脚本扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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