“Undefined variable script”的版本间差异
跳到导航
跳到搜索
无编辑摘要 |
无编辑摘要 |
||
(未显示同一用户的1个中间版本) | |||
第1行: | 第1行: | ||
first file (excutable): |
first file (excutable): |
||
⚫ | |||
echo |
echo $hi |
||
echo |
echo 'OK!' |
||
⚫ | |||
echo 'OK!' |
|||
⚫ | |||
run it and it prints: |
run it and it prints: |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
second file (excutable): |
second file (excutable): |
||
# |
|||
echo 'this is tete' |
|||
# |
|||
echo |
echo $hi |
||
echo |
echo 'OK!' |
||
⚫ | |||
echo 'OK!' |
|||
⚫ | |||
run it and it prints: |
run it and it prints: |
||
this is tete |
|||
⚫ | |||
⚫ | |||
⚫ | |||
Because 1st file have no "#"/"#!/bin/sh"/"#!/bin/csh" on the first line, |
Because 1st file have no "#"/"#!/bin/sh"/"#!/bin/csh" on the first line, |
||
in most of the linux distributions, the default interpreter of a script is /bin/sh |
in most of the linux distributions, the default interpreter of a script is /bin/sh |
2013年12月18日 (三) 11:14的最新版本
first file (excutable):
echo 'this is tete' echo $hi echo 'OK!' exit
run it and it prints:
this is tete OK!
second file (excutable):
# echo 'this is tete' echo $hi echo 'OK!' exit
run it and it prints:
this is tete hi: Undefined variable.
Because 1st file have no "#"/"#!/bin/sh"/"#!/bin/csh" on the first line, in most of the linux distributions, the default interpreter of a script is /bin/sh if it is not specified, and /bin/sh DOES NOT think an undefined variable is a problem! "#" will call csh, and print the problem.