重击:“找不到命令"简单变量分配 [英] Bash: "command not found" on simple variable assignment

查看:59
本文介绍了重击:“找不到命令"简单变量分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的脚本的简单版本,其中显示了失败:

Here's a simple version of my script which displays the failure:

#!/bin/bash
${something:="false"}
${something_else:="blahblah"}
${name:="file.ext"}

echo ${something}
echo ${something_else}
echo ${name}

当我回显变量时,我得到输入的值,但它也会发出错误.我在做什么错了?

When I echo the variables, I get the values I put in, but it also emits an error. What am I doing wrong?

输出:

./test.sh: line 3: blahblah: command not found
./test.sh: line 4: file.ext: command not found
false
blahblah
file.ext

前两行将被发送到stderr,而后三行将被输出到stdout.

The first two lines are being emitted to stderr, while the next three are being output to stdout.

我的平台是fedora 15,bash版本4.2.10.

My platform is fedora 15, bash version 4.2.10.

推荐答案

将变量本身放在一行上将执行存储在该变量中的命令.同时执行任务是偶然的.

Putting a variable on a line by itself will execute the command stored in the variable. That an assignment is being performed at the same time is incidental.

简而言之,不要那样做.

In short, don't do that.

echo ${something:="false"}
echo ${something_else:="blahblah"}
echo ${name:="file.ext"}

这篇关于重击:“找不到命令"简单变量分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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