0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Linux入門 2-3 関数、ローカル変数、グローバル変数

Last updated at Posted at 2021-12-06


[Linux Professional Institute公式HP]:https://www.lpi.org/ja/our-certifications/lpic-1-overview
[Udemy]:https://udemy.benesse.co.jp/career/workstyle/lpic-interview-company.html
[Udemyの動画講座]:https://www.udemy.com/course/linuxlpic/?utm_source=bene-content-marketing&utm_campaign=normal&utm_content=story&utm_term=career&utm_medium=udemyads
[Linux入門 2-2]:https://qiita.com/hoglet/items/4210fe95f8dfb7067b74
[Linux入門 2-4]:https://qiita.com/hoglet/items/152c3c9c711911e6d9c8

はじめに

Linux初学者である自分向け用の記事です。[Udemyの動画講座]を参考にしました。
僕の勉強法は動画を見る実際に動かしてみる問題演習という流れです。

前回まで:[Linux入門 2-2]


2. シェルスクリプト(問題、テスト、演習、発展問題)

2-8. 関数
ファイルの中身
[test@ advance]$ cat ad1.sh 
#!/bin/bash
function hello(){
  echo 'hello world'
  echo $1
}
hello 'Who am I?'
実行結果
[test@ advance]$ ./ad1.sh 
hello world
Who am I?
2-9. ローカル変数、グローバル変数
ローカル変数
ファイルの名前
[test@ advance]$ cat ad1.sh 
#!/bin/bash
function set_name(){
 local name=$1
 echo local: $name
}
echo $1
name='Taro'
echo before: $name
set_name 'Mike'
echo after: $name
実行結果
[test@ advance]$ ./ad1.sh hanako
hanako
before: Taro
local: Mike
after: Taro
グローバル変数
ファイルの中身
[test@ advance]$ cat ad1.sh 
#!/bin/bash
function set_name(){
  name=$1
}
echo $1
name='Taro'
echo before: $name
set_name 'Mike'
echo after: $name
実行結果
[test@ advance]$ ./ad1.sh hanako
hanako
before: Taro
after: Mike

To Be Continued...
[Linux入門 2-4]


0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?