"Bash"의 두 판 사이의 차이

ph
이동: 둘러보기, 검색
1번째 줄: 1번째 줄:
= [[Bash/manual]]  =
 
  
<source lang="bash">
+
==manual, refs==
$ echo {d..h}
+
*[[man/bash]]
 +
*[http://tldp.org/LDP/abs/html/index.html Mendel Cooper - Advanced Bash-Scripting Guide (aka. ABS)] ([http://wiki.kldp.org/HOWTO/html/Adv-Bash-Scr-HOWTO/index.html 한글판])
 +
*[http://www.gnu.org/software/bash/manual/bash.html Bash Reference Manual]
 +
*[http://web.mit.edu/gnu/doc/html/features_toc.html#SEC1 bash features]
 +
*[http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html#toc7 BASH Programming - Introduction HOW-TO] ★
 +
*[http://tldp.org/LDP/Bash-Beginners-Guide/html/index.html Bash Guide for Beginners]
 +
*[http://www.linuxconfig.org/Bash_scripting_Tutorial Bash scripting Tutorial]
 +
 
 +
 
 +
 
 +
==bash expansion : ranges==
 +
<pre>$ echo {d..h}
 
d e f g h
 
d e f g h
  
 
$ echo {d..Z}
 
$ echo {d..Z}
d c b a _ ^ ]  [ Z
+
d c b a _ ^ ]  [ Z</pre>
 +
For more information, refer [http://wiki.bash-hackers.org/syntax/expansion/brace#ranges wiki.bash-hackers.org].
 +
 
 +
 
  
### cp file1 file2와 같다
+
== redirection ==
$ cat < file1 > file2
+
<pre>### cp file1 file2와 같다
 +
$ cat < file1 > file2</pre>
  
$ cut -d: -f1 < /etc/password | sort
 
  
### man nice
 
$ nice
 
  
</source>  
+
==<code>nice</code>==
 +
<pre>Usage: nice [OPTION] [COMMAND [ARG]...]
 +
Run COMMAND with an adjusted niceness, which affects process scheduling.
 +
With no COMMAND, print the current niceness.  Niceness values range from
 +
-20 (most favorable to the process) to 19 (least favorable to the process).</pre>
  
  
  
<source lang="bash">
+
==string : <code><nowiki>$''</nowiki></code>==
$ # Single quotation in single qoute
+
<pre>$ # Single quotation in single qoute
 
$ # http://stackoverflow.com/a/16605140/766330
 
$ # http://stackoverflow.com/a/16605140/766330
 
$ echo \'sdlfkjsldf\' | sed $'s/\'//'
 
$ echo \'sdlfkjsldf\' | sed $'s/\'//'
27번째 줄: 42번째 줄:
 
$ #  $'string' : this is special.
 
$ #  $'string' : this is special.
 
$ #  below line won't work.
 
$ #  below line won't work.
$ #  echo \'sdlfkjsldf\' | sed 's/\'//'
+
$ #  echo \'sdlfkjsldf\' | sed 's/\'//‘</pre>
 +
[http://stackoverflow.com/a/16605140/766330]
 +
 
  
  
$ # 'or'  
+
==or==
 +
<pre>$ # 'or'  
 
$ if [ -z "$1" ] || [ -z "$2" ]; then
 
$ if [ -z "$1" ] || [ -z "$2" ]; then
 
>    echo "Usage: `basename $0` rslt_file target_folder"
 
>    echo "Usage: `basename $0` rslt_file target_folder"
> fi
+
> fi</pre>
 
+
ref. [http://www.tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html expressions used with if]
 
 
$ # for each line of file
 
$ # do not use 'cat' & 'foreach'
 
$ # use 'read'
 
$ # http://stackoverflow.com/a/1521498/766330
 
$ while read line; do
 
>   echo $line
 
> done < textfile.txt
 
 
 
</source>
 
 
 
[http://www.tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html expressions used with if]
 

2017년 3월 30일 (목) 23:41 판

manual, refs


bash expansion : ranges

$ echo {d..h}
d e f g h

$ echo {d..Z}
d c b a _ ^ ]  [ Z

For more information, refer wiki.bash-hackers.org.


redirection

### cp file1 file2와 같다
$ cat < file1 > file2


nice

Usage: nice [OPTION] [COMMAND [ARG]...]
Run COMMAND with an adjusted niceness, which affects process scheduling.
With no COMMAND, print the current niceness.  Niceness values range from
-20 (most favorable to the process) to 19 (least favorable to the process).


string : $''

$ # Single quotation in single qoute
$ # http://stackoverflow.com/a/16605140/766330
$ echo \'sdlfkjsldf\' | sed $'s/\'//'
sdlfkjsldf'
$ #   $'string' : this is special.
$ #   below line won't work.
$ #   echo \'sdlfkjsldf\' | sed 's/\'//‘

[1]


or

$ # 'or' 
$ if [ -z "$1" ] || [ -z "$2" ]; then
>    echo "Usage: `basename $0` rslt_file target_folder"
> fi

ref. expressions used with if