如何在Bash中用引号引起来的字符串中使用环境变量 [英] How to use an environment variable inside a quoted string in Bash

查看:137
本文介绍了如何在Bash中用引号引起来的字符串中使用环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在bash脚本中尝试了以下各种形式:

I've tried various forms of the following in a bash script:

#!/bin/bash
svn diff $@ --diff-cmd /usr/bin/diff -x "-y -w -p -W $COLUMNS"

但是我无法正确地扩展COLUMNS环境变量的语法.

But I can't get the syntax to correctly expand the COLUMNS environment variable.

我尝试了以下各种形式:

I've tried various forms of the following:

svn diff $@ --diff-cmd /usr/bin/diff -x '-y -w -p -W $COLUMNS'

svn diff $@ --diff-cmd /usr/bin/diff -x '-y -w -p -W ${COLUMNS}'

eval svn diff $@ --diff-cmd /usr/bin/diff -x "-y -w -p -W $COLUMNS"

建议?

推荐答案

如果不确定,您可能会在终端上使用"cols"请求,而忘记了"COLUMNS":

If unsure, you might use the 'cols' request on the terminal, and forget COLUMNS:

COLS=$(tput cols)

这篇关于如何在Bash中用引号引起来的字符串中使用环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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