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"