bash : 错误的替换 [英] bash : Bad Substitution

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

问题描述

#!/bin/bash

jobname="job_201312161447_0003"
jobname_pre=${jobname:0:16}
jobname_post=${jobname:17}

这个 bash 脚本在 ubuntu 上给了我错误的替换错误.任何帮助将不胜感激.

This bash script gives me Bad substitution error on ubuntu. Any help will be highly appreciated.

推荐答案

Ubuntu 下的默认 shell (/bin/sh) 指向 dash,而不是 bash.

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 运行它,或者如果你用 bash 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 行将被忽略,脚本将由 dash 解释,它不支持该字符串替换语法.

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.

这篇关于bash : 错误的替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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