gpt4 book ai didi

string - 庆典 : Bad Substitution

转载 作者:太空宇宙 更新时间:2023-11-04 12:59:17 24 4
gpt4 key购买 nike

#!/bin/bash

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

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

最佳答案

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

me@pc:~$ readlink -f $(which sh)
/bin/dash

因此,如果您 chmod +x your_script_file.sh 然后使用 ./your_script_file.sh 运行它,或者如果您使用 bash your_script_file.sh 运行它,它应该可以正常工作。

使用 sh your_script_file.sh 运行它不会工作,因为 hashbang 行将被忽略并且脚本将由 dash 解释,它不支持该字符串替换语法。

关于string - 庆典 : Bad Substitution,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34699667/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com