I117 II I117 PROGRAMMING PRACTICE II SCRIPT LANGUAGE 1 Research Center for Advanced Computing Infrastructure (RCACI) / Yasuhiro Ohara

Similar documents
/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1

syspro-0405.ppt

I117 II I117 PROGRAMMING PRACTICE II SOFTWARE DEVELOPMENT ENV. 1 Research Center for Advanced Computing Infrastructure (RCACI) / Yasuhiro Ohara

I117 II I117 PROGRAMMING PRACTICE II DEBUG Research Center for Advanced Computing Infrastructure (RCACI) / Yasuhiro Ohara

I117 II I117 PROGRAMMING PRACTICE II HASH Research Center for Advanced Computing Infrastructure (RCACI) / Yasuhiro Ohara

I117 II I117 PROGRAMMING PRACTICE II 2 SOFTWARE DEVELOPMENT ENV. 2 Research Center for Advanced Computing Infrastructure (RCACI) / Yasuhiro Ohara yasu

Introduction Purpose This training course demonstrates the use of the High-performance Embedded Workshop (HEW), a key tool for developing software for

-2 gnuplot( ) j ( ) gnuplot /shell/myscript 1

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental data structures /06/14(Tue) / Memory Management

unix15-script2_09.key

シェルプログラミング コマンドをパイプでつなげるだけでは済まないような ある程度まとまった処理を複数のコマンドを制御構文を用いたりしてファイルとしたものを ( シェル ) スクリプトと呼ぶ シェルプログラム バッチなどともいう.bash_profile もシェルスクリプトなので このファイルを解読し

PBASIC 2.5 PBASIC 2.5 $PBASIC directive PIN type New DEBUG control characters DEBUGIN Line continuation for comma-delimited lists IF THEN ELSE * SELEC

,,,,., C Java,,.,,.,., ,,.,, i

GNU Emacs GNU Emacs

X Window System X X &

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

AN 100: ISPを使用するためのガイドライン

Introduction Purpose This training course describes the configuration and session features of the High-performance Embedded Workshop (HEW), a key tool

Compatibility list: vTESTstudio/CANoe

Asterisk PBX 不正利用防止

28 Docker Design and Implementation of Program Evaluation System Using Docker Virtualized Environment

Windows Cygwin Mac *1 Emacs Ruby ( ) 1 Cygwin Bash Cygwin Windows Cygwin Cygwin Mac 1 Mac 1.2 *2 ls *3 *1 OS Linux *2 *3 Enter ( ) 2

fx-9860G Manager PLUS_J

25 II :30 16:00 (1),. Do not open this problem booklet until the start of the examination is announced. (2) 3.. Answer the following 3 proble

UNIX


Systemwalker IT Service Management Systemwalker IT Service Management V11.0L10 IT Service Management - Centric Manager Windows

Java updated

A

unix.dvi

1 I EViews View Proc Freeze


Microsoft Word - Win-Outlook.docx

¥¤¥ó¥¿¡¼¥Í¥Ã¥È·×¬¤È¥Ç¡¼¥¿²òÀÏ Âè11²ó

TC5.ids


C H H H C H H H C C CUTION:These telephones are for use in Japan only. They cannot be used in other countries because of differences in voltages, tele

取説_VE-PV11L(応用編)

LAN Copyright c Daikoku Manabu This tutorial is licensed under a Creative Commons Attribution 2.1 Japan License

¥×¥í¥°¥é¥ß¥ó¥°±é½¬I Exercise on Programming I [1zh] ` `%%%`#`&12_`__~~~ alse

2002 awk Aho,Weinberger,Kernighan DFA awk Brian Kernighan DFA GNU awk Arnold Robbins DFA NFA MKS awk Mortice Kern Systems POSIX NFA mawk Mike Brennan

プレポスト【解説】

273? C

外国語教育/斎藤

untitled

Introduction Purpose This course explains how to use Mapview, a utility program for the Highperformance Embedded Workshop (HEW) development environmen

Copyright Oracle Parkway, Redwood City, CA U.S. GOVERNMENT END USERS: Oracle programs, including any operating system, integrated softw

Ver.1 1/17/2003 2

日本語教育紀要 7/pdf用 表紙

main.dvi


Introduction Purpose The course describes library configuration and usage in the High Performance Embedded Workshop (HEW), which speeds development of


RR-US470 (RQCA1588).indd

TEX American Mathematical Society PostScript Adobe Systems Incorporated

たのしいプログラミング Pythonではじめよう!

SCM (v0201) ( ) SCM 2 SCM 3 SCM SCM 2.1 SCM SCM SCM (1) MS-DOS (2) Microsoft(R) Windows 95 (C)Copyright Microsoft Corp

Microsoft Word - Meta70_Preferences.doc

\615L\625\761\621\745\615\750\617\743\623\6075\614\616\615\606.PS

はじめに

How to read the marks and remarks used in this parts book. Section 1 : Explanation of Code Use In MRK Column OO : Interchangeable between the new part

2.4.7 \ AWK AWK......

dvi

How to read the marks and remarks used in this parts book. Section 1 : Explanation of Code Use In MRK Column OO : Interchangeable between the new part

1. 1 DBMS Unix (USP ) ( )[3] 20 UNIX [2] KISS UNIX 1. 2 (Tukubai ) Unix OS Unix USP Tukubai Tukubai 1. 3 Unix SQL Tukubai usp Tukubai Open usp Tukubai

1st-session key

How to read the marks and remarks used in this parts book. Section 1 : Explanation of Code Use In MRK Column OO : Interchangeable between the new part

How to read the marks and remarks used in this parts book. Section 1 : Explanation of Code Use In MRK Column OO : Interchangeable between the new part

L3 Japanese (90570) 2008

haskell.gby


Microsoft Word - D JP.docx

206“ƒŁ\”ƒ-fl_“H„¤‰ZŁñ

2

2

ストラドプロシージャの呼び出し方

(CC Attribution) Lisp 2.1 (Gauche )

f(x) x S (optimal solution) f(x ) (optimal value) f(x) (1) 3 GLPK glpsol -m -d -m glpsol -h -m -d -o -y --simplex ( ) --interior --min --max --check -

listings-ext

I I / 68

超初心者用

評論・社会科学 84号(よこ)(P)/3.金子

2

外部SQLソース入門

tebiki00.dvi

program.dvi

L1 What Can You Blood Type Tell Us? Part 1 Can you guess/ my blood type? Well,/ you re very serious person/ so/ I think/ your blood type is A. Wow!/ G


A : kerl kerl Erlang/OTP Erlang/OTP 2 2 Elixir/Phoenix URL 2 PDF A.2 Bash macos.bash_profile exp

自然言語処理16_2_45


joho12.ppt

Read the following text messages. Study the names carefully. 次のメッセージを読みましょう 名前をしっかり覚えましょう Dear Jenny, Iʼm Kim Garcia. Iʼm your new classmate. These ar

生研ニュースNo.132

第5回お試しアカウント付き並列プログラミング講習会

VE-GP32DL_DW_ZA

エレクトーンのお客様向けiPhone/iPad接続マニュアル

NSR-500 Installation Guide

1 ( 8:12) Eccles. 1:8 2 2

WE WESB WENB WESNB 428

Transcription:

I117 II I117 PROGRAMMING PRACTICE II SCRIPT LANGUAGE 1 Research Center for Advanced Computing Infrastructure (RCACI) / Yasuhiro Ohara yasu@jaist.ac.jp

/ SCHEDULE 1. 2011/06/07(Tue) / Basic of Programming 2. 2011/06/09(Thu) / Fundamental data structures 3. 2011/06/14(Tue) / Memory Management 1 4. 2011/06/16(Thu) / Memory Management 2 5. 2011/06/21(Tue) / Debugging 6. 2011/06/23(Thu) / Software Development Env. 1 7. 2011/06/28(Tue) / Software Development Env. 2 8. 2011/06/30(Thu) / Data Structure : Tree 9. 2011/07/05(Tue) / Data Structure: Hash 10. 2011/07/07(Thu) / Understanding Programs 1 11. 2011/07/12(Tue) / Understanding Programs 2 12. 2011/07/14(Thu) / Script Language 1 13. 2011/07/19(Tue) / Script Language 2 14. 2011/07/21(Thu) / Other Languages 15. 2011/07/26(Tue) / Examination

/ FINAL REPORT free topic : The deadline: 7/26(Tue) Submit the source code, and the report. by e-mail: i117report@jaist.ac.jp by 7/26(Tue) 23:59. / Sound file converter / web crawler (CalDAV) calendar program new shell, editor, window manager rsync encrypt/decrypt, rsync markov-chain program The final report must have deep consideration

/ TODAY'S INDEX sh shell builtins test, expr sed awk autoconf

/ SCRIPT LANGUAGE: SHELL

/ WHAT IS "SHELL"? UNIX / The interface between the users and the system. / specification POSIX 1003.2 X/Open 4.2 / more extended one shell X Window Other programs UNIX kernel

SHELL / KINDS OF SHELLS sh (Bourne) / original shell csh, tcsh, zsh Berkley UNIXBill JoyC JAISTSparctcsh / C shell is created by Bill Joy who made Berkeley Unix. JAIST's default shell is tcsh. ksh, pdksh bash KornDavid Korn / korn shell and it's public version. rc GNULinuxDarwin(MacOS) / shell by GNU Project. cshc / more C-like shell, a shell in the Plan 9 system.

/ VARIABLES; ASSIGNMENT AND PRINT / no need to define variables / assignment and print =$ / assignment by '=', reference by '$' / example / in command line $ age=22 $ echo $age 22 / in shell script $ cat age.sh age=22 echo $age $ sh age.sh 22

/ QUOTE, ESCAPE SEQUENCE (\) / you can use "'" or "\" when you use special character. $ words= hello world $ echo $words hello world $ words=hello\ world $ echo $world hello world $ words=hello world sh: world: command not found :wordshelloworld This assigns "hello" to "words", and execute a command "world" which does not exist (error).

) SINGLE QUOTATION, DOUBLE QUOTATION. $ / "$" is not evaluated in single quotations. $ name=george $ words= hello $name $ echo $words hello $name $ / "$" is evaluated in double quotations. $ name=george $ words= hello $name $ echo $words hello George

READ / ASSIGNMENT BY 'READ' COMMAND read / interactive assignment by 'read'. $ read name george $ echo $name george

/ SCRIPT EXECUTION AND PERMISSIONS. / give files permissions to be executed. chmod +x / do it by 'chmod +x' $ chmod +x args.sh $ cat args.sh #!/bin/sh words= hello world echo $words echo $words echo $words echo \$words echo Enter your name read name echo hello $name $./args.sh hello world hello world $words $words Enter your name George hello George

/ COMMENT OUT # / '#' by comment out # / comment last from '#' to the end of line. 1 / the first line's comment in the script file has a special purpose. / specify the command to execute the file. #!/bin/sh #!/usr/bin/perl #!/usr/local/bin/ruby 1 / specify the command and attach executable permission; the script will become executable.

/ ENVIRONMENTAL VARIABLE / some initialized in command execution / typical example $HOME / home directory $PATH / command path list $0 / the name of the script $$ / pid of the script $? / return values $C_INCLUDE_PATH Cinclude / list of paths the compiler searches include files $LD_LIBRARY_PATH / list of paths the loader searches the libraries $LIBRARY_PATH / list of paths the linker searches the libraries env / 'env' command will display them.

/ PARAMETER VARIABLE / the argument from command line $1, $2, $3 / the arguments $* $IFS / The array using IFS $@ $*$IFS / The array without IFS $ IFS=: $ set foo bar bam $ echo $1 foo $ echo $@ foo bar bam $ echo $* foo:bar:bam $ unset IFS $ echo $* foo bar bam

TEST([]) / TEST COMMAND / conditions in the shell / comparison of strings $ test hoge = hoge $ echo $? 0 $ test hoge = foo $ echo $? 1 $ test hoge!= foo $ echo $? 0 $ name=geroge $ test n $name # null $ echo $? 0 $ test n $ echo $? 1

TEST / ARITHMETIC COMPARISON / greater or less? $ test 100 eq 100 # $ echo $? 0 $ test 100 eq 200 $ echo $? 1 $ test 100 gt 200 # 100 > 200 $ echo $? 1 $ test 100 le 200 # 100 <= 200 $ echo $? 0 ge, lt, ne,!

TEST / FILE CHECK / existence and file type checks $ touch hoge.txt $ mkdir foo $ test e hoge.txt # $ echo $? 0 $ test f hoge.txt # $ echo $? 0 $ test f foo $ echo $? 1 $ test d foo # $ echo $? 0 g, r, s, w, u, x

IF / IF STATEMENT iftest / use test for condition test[]test / '[ ]' is equivalent to test if test f file.txt; then if [ -f file.txt ]; then [ condtion ] if / if statement if condition then statements elif condition statements else statements fi

IF / EXAMPLE / lock file example lock=/tmp/$0.lock if [ "$1" = "lock" ]; then if [ -f $lock ]; then exit 1 else touch $lock fi elif [ "$1" = "unlock" ]; then if [ -O $lock ]; then rm $lock else exit 1 fi fi

AND, OR & concatenation of conditions if [ condition1 ] && [ condition2 ]; then statements fi if [ condition1 ] [ condition2 ]; then statements fi

FOR / REPETITION BY FOR for / syntax for variable in values do statements done example $ cat for.sh for var in foo bar bam 1234 do echo $var done $ sh for.sh foo bar bam 1234

FORVAR / USE COMMAND'S RESULTS.old / backup (copy) all files to <file>.old $ cat old.sh for var in $(ls); do cp $var $var.old done $ ls bar.txt foo.txt old.sh $ sh old.sh $ ls bar.txt foo.txt bar.txt bar.txt.old foo.txt.old bar.txt.old

WHILEUNTIL / WHILE AND UNTIL while / syntax condition repeated while the condition is true while condition do statements done until / syntax condition / repeated until the condition becomes true until condition do statements done

WHILEN / N-TIMES REPETITION BY WHILE $ cat count.sh i=1 while [ $i le 20 ]; do echo $n i=$(($i+1)) # $(()) done $ sh count.sh 1 2 3 4 5 6...

CASE / PATTERN MATCH BY CASE case / syntax case variable in pattern [ pattern]...) statements pattern [ pattern]...) statements *) statements esac case / example $ cat hello.sh case $1 in morning ) echo good morning! night ) echo good evening! noon evening ) echo hello! esac $ sh hello.sh morning good morning! $ sh hello.sh noon hello!

SHIFTPOP / POPPING ARGUMENTS BY SHIFT shiftpop / an argument is popped by shift $ set foo bar bam $ echo $* foo bar bam $ shift $ echo $* bar bam $ shift $ echo $* bam / process all arguments while [ $1!= ]; do echo $1 done

/ OTHERS break for, while, until / breaks loops continue for, while, until / skip one step in repetitions. source / sources shell script files exec exec / the current shell is replaced with the command man exec expr / arithmetic calculation $(()) / slow than $(())

/ OTHERS trap / signal handler eval / evaluate arguments / generate a script in a script and execute it

SED

AWK

/ LOG COUNT SCRIPT calendar.jaist.ac.jp