Shell Script 의 기본


bash-4.1$ x=3
bash-4.1$ echo $x
3


bash-4.1$ echo "hello     there"
hello     there

bash-4.1$ echo 'hello     there'
hello     there
bash-4.1$ echo hello      there
hello there


bash-4.1$ echo "the value of x:     $x"
the value of x:     3
bash-4.1$ echo 'the value of x:     $x'
the value of x:     $x
bash-4.1$ echo 'I have $10000'
I have $10000


bash-4.1$ echo Today is `date`
Today is Wed Aug 6 12:50:46 EST 2014
bash-4.1$ echo "Today is `date`"
Today is Wed Aug  6 12:51:00 EST 2014




permission

bash-4.1$ ls -l
total 2
-rw-r--r--+ 1 11776352 Students   0 Jul 30 13:06 a.txt
-rw-r--r--+ 1 11776352 Students   0 Jul 30 13:06 c.txt
-rw-r--r--+ 1 11776352 Students 334 Aug  6 12:40 hello.txt

bash-4.1$ chmod 600 a.txt
bash-4.1$ ls -l
total 2
-rw-------+ 1 11776352 Students   0 Jul 30 13:06 a.txt
-rw-r--r--+ 1 11776352 Students   0 Jul 30 13:06 c.txt
-rw-r--r--+ 1 11776352 Students 334 Aug  6 12:40 hello.txt

bash-4.1$ chmod 644 a.txt
bash-4.1$ ls -l
total 2
-rw-r--r--+ 1 11776352 Students   0 Jul 30 13:06 a.txt
-rw-r--r--+ 1 11776352 Students   0 Jul 30 13:06 c.txt
-rw-r--r--+ 1 11776352 Students 334 Aug  6 12:40 hello.txt

first --- user (u)
second --- group (g)
third --- other (o)

0 000
1 001 * execute = 1
2 010 * write = 2
3 011
4 100 * read = 4
5 101
6 110
7 111

readable, writable, executable = 4+2+1 = 7 (rwx)

chmod 755 myfile
chmog o+x myfile
chmog o-x myfile



Script 실행


bash-4.1$ hello.sh
bash: hello.sh: command not found
bash-4.1$ pwd
/home/11776352/usp/2
bash-4.1$ /home/11776352/usp/2/hello.sh
hello world
bash-4.1$ cd ..
bash-4.1$ 2/hello.sh
hello world
bash-4.1$ cd 2/
bash-4.1$ ls
a.txt  c.txt  hello.sh    hello.txt
bash-4.1$ ../2/hello.sh
hello world
bash-4.1$ ./hello.sh
hello world


 Script 응용




저작자 표시
신고

posted by youp_han matrim



티스토리 툴바