如何在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)