1、シェルスクリプトのエントリ

1 スクリプト形式

スクリプト#!/ binに/ bashの冒頭に(指定された分析単位

2 最初のシェルスクリプト:HelloWorldの

1 )需要:作成シェルスクリプトを、出力のhelloworld

2 ケース実用的な操作:

[atguigu @ hadoop101件のデータ] $タッチhelloworld.sh

[Atguigu @ hadoop101件のデータ] $ viのhelloworld.sh

 

helloworld.sh に次のように入力します。

#!/ binに/ bashの

エコー「のHelloWorld」

3 スクリプトの一般的な実装

ディ種: bashの使用またはSH + スクリプト相対または絶対パスは、(スクリプト与えられていない + X 許可)を

SH + 相スクリプトパス

[atguigu @ hadoop101件のデータ] $ shをhelloworld.sh

こんにちは世界

SH + スクリプトの絶対パス

[atguigu @ hadoop101件のデータ] $ shを/home/atguigu/datas/helloworld.sh

こんにちは世界

バッシュ+スクリプトの相対パス

[atguigu @ hadoop101件のデータ] $ bashのhelloworld.sh

こんにちは世界

bashの+スクリプトの絶対パスを

[atguigu @ hadoop101件のデータ] $ bashの/home/atguigu/datas/helloworld.sh

こんにちは世界

最初ジカルボン種類:使用するために、絶対または相対パスを入力するスクリプトを実行するスクリプトは、必要があり、実行権限を持って + X

A )まず、私たちは与えたいhelloworld.sh スクリプト+ X 権限を

[atguigu @ hadoop101件のデータ] $ chmodの777 helloworld.sh

B スクリプトの)実行

相対パス

[atguigu @ hadoop101件のデータ] $ ./helloworld.sh

こんにちは世界

絶対パス

[atguigu @ hadoop101件のデータ] $ /home/atguigu/datas/helloworld.sh

こんにちは世界

注:最初の実行方法は、性質がある bashのパーサあなたは、スクリプトを実行するのに役立つように、スクリプト自体は必要ありません実行権限を。ディ2種類の実行方法は、基本的にスクリプトが必要と独自の実行を順序が実行権限を必要とします。

3。ディのEr Geのシェルスクリプト:マルチコマンド処理

1 )需要

では/ホーム/ atguigu /ディレクトリには、下に作成してbanzhang.txt、banzhang.txtファイルの増加「私はCLSが大好きです」。

2 )ケース実用的な操作:

[atguigu @ hadoop101件のデータ] $タッチbatch.sh

[Atguigu @ hadoop101件のデータ] $ viのbatch.sh

 

batch.sh に次のように入力します。

#!/ binに/ bashの

 

CD /ホーム/ atguigu

タッチcls.txt

「私はCLSを愛して」エコー>> cls.txt

おすすめ

転載: www.cnblogs.com/liuzhonghui/p/12001319.html