庆典:坏换人 [英] bash: Bad Substitution

查看:131
本文介绍了庆典:坏换人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#!/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.

推荐答案

默认的s​​hell( / 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屋!

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