是否可以在bash中没有$的情况下访问环境变量? [英] Is it possible to access environment variables without the '$' in bash?

查看:106
本文介绍了是否可以在bash中没有$的情况下访问环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这看似微不足道,但是我是bash脚本的新手,在其他地方找不到答案。

This may seem pretty trivial but I am a novice in bash scripting and I could not find the answer elsewhere.

我有 mplayer 安装在ubuntu 13.04上,我正在用它来流媒体互联网广播电台。通常,您需要为此提供ip作为参数:

I have mplayer installed on ubuntu 13.04 and I am using it to stream internet radio stations. Normally you need to provide the ip as argument for that:

mplayer http://176.31.113.37:8080

我已经在根 .bash_aliases 中创建了一个别名文件。具有以下内容:

I have created an aliases file in root .bash_aliases where I have the following:

export SOMA="http://173.239.76.147:8090"
export FRESH="http://176.31.113.37:8080"

现在我只能使用电台名称播放收音机: mplayer $ FRESH
我想知道是否可以摆脱 $ 符号,同时使用命令 mplayer FRESH 例如。

Now I can play the radio using only the station name: mplayer $FRESH. I was wondering is it possible to get rid of the $ sign also to use the command mplayer FRESH for example.

谢谢!

推荐答案

如果使用变量您需要 $ 进行扩展。我会用别名而不是变量来做到这一点。考虑这样的事情:

If you are using variables you need the $ to expand it. I would do this with aliases though, not variables. Consider something like this:

alias mpsoma='mplayer http://192.168.1.1:8090'

然后只需键入 mpsoma 即可运行完整命令。

Then just type mpsoma to run the full command.

这篇关于是否可以在bash中没有$的情况下访问环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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