Shell ' + + ' operator error and Let:not found error resolution

Source: Internet
Author: User

Today, the script on the company server to get its own notebook on the run error, set-x tracking discovery is a variable in the self-increase operation error occurred, the error section of the script is probably like this:

#! /bin/sh  
param=0  
echo $ ((param++))
Error message:

$/test.sh   
./test.sh:3:./test.sh:arithmetic expression:expecting Primary: "param++"
There is still an error after replacing (()) in the script with the Let command:

#! /bin/sh  
param=0 let  
param++
Echo $param
Error message:

$/test.sh   
./test.sh:4:./test.sh:let:not found
The script runs correctly on the server, but there is something wrong with your notebook, so it must be the environment on your laptop that is different from the server. My notebook is Ubuntu 16.04, and the server is CentOS, which may be the breakthrough point. Later, after looking, I found that the/bin/sh link in Ubuntu is pointing to the dash shell by default, and the server is pointing at the bash shell. The dash is a small shell, and his function is naturally not bash strong, the above problem is with the dash shell does not support + + operations and let command caused.

Found the reason, the solution is very simple. By directly indicating the use of the bash shell in the script, change the first line of the script to:

#! /bin/bash
# Script Content
# ...
or point/bin/sh directly to bash to fix the problem and enter the command at the terminal:

$: sudo ln-sf/bin/bash/bin/sh






Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.