庆典:坏换人 [英] bash: Bad Substitution
问题描述
#!/bin/bash
jobname="job_201312161447_0003"
jobname_pre=${jobname:0:16}
jobname_post=${jobname:17}
本bash脚本给我的坏替代的Ubuntu的错误。任何帮助将是非常美联社preciated。
This bash script gives me Bad substitution error on Ubuntu. Any help will be highly appreciated.
推荐答案
默认的shell( / bin / sh的
)Ubuntu下点破折号
,而不是庆典
。
The default shell (/bin/sh
) under Ubuntu points to dash
, not bash
.
me@pc:~$ readlink -f $(which sh)
/bin/dash
所以,如果你搭配chmod + X your_script_file.sh
,然后用 ./ your_script_file.sh
运行,或如果您使用庆典your_script_file.sh
运行它,它应该工作正常。
So if you chmod +x your_script_file.sh
and then run it with ./your_script_file.sh
, or if you run it with bash your_script_file.sh
, it should work fine.
与 SH your_script_file.sh
运行它不会工作,因为hashbang线将被忽略和脚本将由 PTED间$ P $破折号
,它不支持该字符串替换语法。
Running it with sh your_script_file.sh
will not work because the hashbang line will be ignored and the script will be interpreted by dash
, which does not support that string substitution syntax.
这篇关于庆典:坏换人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!