A problem caused by mixed shell

Source: Internet
Author: User
An error is reported when a sh is started in debian today, which leads to the formation of this article: when bashshell is used, we have the following scenario: env. sh -- define public variable run1.sh -- define run code run2.sh -- define run code if env. sh...

An error is reported when a sh is started in debian today, which leads to the formation of this article:

 


When using bash shell, we have the following scenarios:

Env. sh -- define public variables


Run1.sh -- define the running code

Run2.sh -- define the running code

 

 

If the content in env. sh changes according to the specific run *. sh, you need to input a variable to env. sh.

Many may adopt this method,

 


Scenario simulation:


Env. sh:

View plaincopy to clipboardprint? #! /Bin/sh
Echo $1
#! /Bin/sh
Echo $1

 


Run1.sh:
View plaincopy to clipboardprint? #! /Bin/sh
 
CURRENT_PATH = 'core'
 
Echo $ {CURRENT_PATH}
 
./Home/admin/tmp/madding. lip/env. sh $ CURRENT_PATH
 
Echo "invoke $ CURRENT_PATH-service $1"
 
If ["$1" = "stop"]; then
Echo "'date': stop --------------------------------"
Echo "remove $ shutdownFile"
Elif ["$1" = "debug"]; then
Echo "'date': debug --------------------------------"
Fi
#! /Bin/sh

CURRENT_PATH = 'core'

Echo $ {CURRENT_PATH}

./Home/admin/tmp/madding. lip/env. sh $ CURRENT_PATH

Echo "invoke $ CURRENT_PATH-service $1"

If ["$1" = "stop"]; then
Echo "'date': stop --------------------------------"
Echo "remove $ shutdownFile"
Elif ["$1" = "debug"]; then
Echo "'date': debug --------------------------------"
Fi

 

 

Run the following command:

Sh run. sh start

 


Result:

On redhat 5.3:

Core
Core
Invoke core-service

 

Debian 6:

Core

Start

Invoke core-service

 

 

 

Analysis:

 

 

The problem is:


View plaincopy to clipboardprint ?. /Home/admin/tmp/madding. lip/env. sh $ CURRENT_PATH
./Home/admin/tmp/madding. lip/env. sh $ CURRENT_PATH

 


Fundamentals:

Default debian:

View plaincopy to clipboardprint? Madding @ wmmad :~ $ Which sh
/Bin/sh
Madding @ wmmad :~ $ Ls-l/bin/sh
Lrwxrwxrwx 1 root 4 Jun 6 05:49/bin/sh-> dash
Madding @ wmmad :~ $ Which sh
/Bin/sh
Madding @ wmmad :~ $ Ls-l/bin/sh
Lrwxrwxrwx 1 root 4 Jun 6 05:49/bin/sh-> dash

Redhat default sh usage:

View plaincopy to clipboardprint? [Admin @ **** ~] $ Which sh
/Bin/sh
[Admin @ **** ~] $ Ls-l/bin/sh
Lrwxrwxrwx 1 root 4-Nov 16 2010/bin/sh-> bash
[Admin @ **** ~] $ Which sh
/Bin/sh
[Admin @ **** ~] $ Ls-l/bin/sh
Lrwxrwxrwx 1 root 4-Nov 16 2010/bin/sh-> bash

 

 


Handling suggestion:

1. shell should be written in a compatible way as much as possible, so it is more portable.

2. if the shell is explicitly used, it should be indicated in the header as much as possible, so that the specific shell can be identified during the./method execution.

3. if you use a specific shell Step-by-step method for execution, it is recommended to specify the parser for shell step, such as dash xx. sh or bash xx. sh.

Author "madding. lip"
 

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.