如何使用环境变量在bash脚本引用字符串内 [英] How to use environment variable inside a quoted string in BASH script

查看:127
本文介绍了如何使用环境变量在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"

但我不能让语法正确展开环境变量。

我已经试过各种形式如下:

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的要求,而忘记列:

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

COLS=$(tput cols)

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

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