shell - 回显一个带有变量的字符串,该变量也是一个字符串和变量,并且为空白但不起作用
问题描述
我正在构建一个应该用正确的颜色回显消息的函数,但在我的代码中似乎不起作用。
代码如下:
#!/bin/bash
function green() {
echo -e "\033[32m[ $1 ]\033[0m"
}
function software_is_installed() {
local message="software is installed with name:"$1
blue $message
}
green ssh
输出不是预期的,但是
[ software ]
但在另一个代码片段中它工作正常。代码如下:
#!/bin/bash
function blue() {
echo -e "\033[34m[ $1 ]\033[0m"
}
function file_or_dir_already_exists() {
blue "file or directory: $1 already exists"
}
file_or_dir_already_exists ~/
它按预期输出,输出如下
[ file or directory: ~/ already exists ]
我期待类似的东西
software is installed with name: ssh
解决方案
尝试像这样修改:
#!/bin/bash
function green() {
echo -e "\033[32m[ $1 ]\033[0m"
}
function software_is_installed() {
green "software is installed with name: $1"
}
software_is_installed ssh
推荐阅读
- python - 无法使用 XPATH 在 Facebook 中找到搜索栏元素
- ipython - 有人可以解释一下“!”是怎么做的吗?和“%%”命令在 python 中工作?
- swift - MCBrowserViewController 不应该在浏览器中收到此回调消息?
- docker - 不能在之前安装过的 docker 容器中使用 curl
- html - 在其父元素的中间垂直显示一个元素
- encoding - 无法将带有西里尔数据的 csv 文件上传到谷歌数据工作室 - 编码 utf-8 错误
- git - 我可以用它的前辈之一压缩合并提交吗?
- html - 为什么在内容流方面有错误的大小?
- java - 有什么方法可以从 Java 或 Kotlin 读取 Python pickle (test1.pickle)?
- logging - 用于不同子应用的更大多个接收器