“让"内部 shell 命令在 shell 脚本中不起作用? [英] "let" internal shell command doesn't work in a shell script?

查看:27
本文介绍了“让"内部 shell 命令在 shell 脚本中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做到了

a=1234 
let "a=a+1"

在命令行上,没问题.但是当我在 shell 脚本中做同样的事情时.它打印出让:未找到"的错误.这是脚本文件.

on command line and it's fine. But when I do the same in a shell script. It prints out an error that "let: not found". Here is the script file.

#!/bin/sh
a=1234;
let "a=a+1";
echo "$a";

谢谢,

推荐答案

问题很可能是 /bin/sh 与您的普通 shell 不一样,或者行为不一样.例如,当 bash 被调用为 /bin/sh 时,它提供了其正常功能的一个子集.

The problem is likely that /bin/sh is not the same as, or does not behave the same as, your normal shell. For example, when bash is invoked as /bin/sh, it provides a subset of its normal features.

因此,您可能需要更改 shebang 行以使用不同的 shell:

So, you may need to change your shebang line to use a different shell:

#!/bin/bash

#!/bin/ksh

行尾不需要分号.

这篇关于“让"内部 shell 命令在 shell 脚本中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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