字符串替换在bash - 坏替代误差 [英] String replacement in bash - bad substitution error

查看:162
本文介绍了字符串替换在bash - 坏替代误差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在新受bash脚本编程,但我不uderstand为什么它不能正常工作

I newbie in bash scripting but i don't uderstand why it's not work

#!/bin/bash
foo=foobarfoobar
echo ${foo//bar/baz}

第3行不良替代误差

bad substitution error on line 3

推荐答案

这在替代猛砸4.2.8工作正常(和看起来很好根据文档)。

That substitution works fine in Bash 4.2.8 (and looks fine according to the documentation).

我最好的猜测是,你实际上并不使用bash - 你是如何调用脚本?如果你正在做 SH script.sh 你可能用破折号或类似的东西运行它(和短跑确实给第3行替换错误)。尽量明确地击(的bash script.sh )。

My best guess would be that you're not actually using Bash - how are you invoking the script? If you're doing sh script.sh you may well be running it with Dash or something similar (and Dash does indeed give a substitution error on line 3). Try explicitly running it with Bash (bash script.sh).

如果事实证明你实际使用的是短跑,有上的差异,以及如何回去使用bash(如果你想)在这里一些有用的信息:的https://wiki.ubuntu.com/DashAsBinSh

If it turns out you are actually using Dash, there's some useful information on the differences and how to go back to using Bash (if you want to) here: https://wiki.ubuntu.com/DashAsBinSh

这篇关于字符串替换在bash - 坏替代误差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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