> echo $0 -bash
/ >pushd /usr/ /usr ~ /usr >pushd local /usr/local /usr ~ /usr/local >pushd bin /usr/local/bin /usr/local /usr ~ /usr/local/bin >popd /usr/local /usr ~ /usr/local >popd /usr ~ /usr >popd ~ / >popd bash: popd: directory stack empty / >
Foreground Background Shell --[ > Command ] --> JOB ---- [Ctrl+Z] ---> JOB(Sleepgin) (Running) <--- [ > fg ] ---- ¡Ã [ > bg ] ¢ Shell --[ > Command & ] --------------------------> JOB(Runnging)
´Ä¶ÊÑ¿ô PS1 ¤Ë¼¡¤Îʸˡ¤Ç¥×¥í¥ó¥×¥È¤Ë½Ð¤·¤¿¤¤¤â¤Î¤òÄêµÁ¤¹¤ë
\a | ASCII ¤Î¥Ù¥ëʸ»ú (07) |
\d | "ÍËÆü ·î Æü"¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤Ë¤è¤ëÆüÉÕ¤± (Îã "Tue May 26") |
\e | ASCII ¤Î¥¨¥¹¥±¡¼¥×ʸ»ú (033) |
\h | ºÇ½é¤Î"."¤Î¤È¤³¤í¤Þ¤Ç¤Î¥Û¥¹¥È̾ |
\H | ¥Û¥¹¥È̾ |
\n | ²þ¹Ô |
\r | Éüµ¢ |
\s | ¥·¥§¥ë̾¡¢$0 ¤Î¥Ù¡¼¥¹Ì¾ (ºÇ¸å¤Î¥¹¥é¥Ã¥·¥å¤Î¸å¤í¤ÎÉôʬ) |
\t | 24»þ´ÖÀ©¤Î HH:MM:SS ¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤Ë¤è¤ë»þ´Ö |
\T | 12»þ´ÖÀ©¤Î HH:MM:SS ¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤Ë¤è¤ë»þ´Ö |
\@ | am/pm ¤ò¤Ä¤±¤¿12»þ´ÖÀ©¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤Ë¤è¤ë»þ´Ö |
\u | ¸½¥æ¡¼¥¶¡¼¤Î¥æ¡¼¥¶¡¼Ì¾ |
\v | bash ¤Î¥Ð¡¼¥¸¥ç¥ó(Îã 2.00) |
\V | bash ¤Î¥ê¥ê¡¼¥¹Èֹ桢¥Ð¡¼¥¸¥ç¥ó¤È¥Ñ¥Ã¥Á¥ì¥Ù¥ë (Îã 2.00.0) |
\w | ¸½ºß¤Î¥Ç¥£¥ì¥¯¥È¥ê |
\W | ¸½ºß¤Î¥Ç¥£¥ì¥¯¥È¥ê¤Î¥Ù¡¼¥¹Ì¾ |
\! | ¸½ºß¤Î¥³¥Þ¥ó¥É¤Î¥Ò¥¹¥È¥ê¡¼ÈÖ¹æ |
\# | ¸½ºß¤Î¥³¥Þ¥ó¥É¤Î¥³¥Þ¥ó¥ÉÈÖ¹æ |
\$ | UID¤¬0¤Ê¤é#¡¢¤½¤¦¤Ç¤Ê¤±¤ì¤Ð$ |
\nnn | 8¿Ê¿ônnn¤ËÂбþ¤¹¤ëʸ»ú |
\\ | ¥Ð¥Ã¥¯¥¹¥é¥Ã¥·¥å |
\[ | ɽ¼¨¤µ¤ì¤Ê¤¤Ê¸»úÎó¤Î³«»Ï¡£Ã¼ËöÀ©¸æ¥·¡¼¥±¥ó¥¹¤ò¥×¥í¥ó¥×¥È¤ËËä¤á¹þ¤à¡£ |
\] | ɽ¼¨¤µ¤ì¤Ê¤¤Ê¸»úÎó¤Î½ª¤ê¡£ |
Îã:
export PS1="[\w]\$ "
[/opt/local/java/db-derby-10.3.3.0]$ ls CHANGES.html docs KEYS frameworks LICENSE frameworks.DEPRECATED.txt NOTICE index.html RELEASE-NOTES.html javadoc bin lib demo test [/opt/local/java/db-derby-10.3.3.0]$
#!/bin/bashLinux¤Ç¤Ï¡¢/bin/sh ¤Ï /bin/bash ¤Î¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯¤Ê¤Î¤Ç /bin/sh ¤È¤·¤Æ¤âÎɤ¤¤¬¡¢Solaris¤Ç¤ÏÊÌʪ¡£sh ¤È bash ¤Ç¡¢testʸ¤Î¿¶¤ëÉñ¤¤¤¬°ã¤Ã¤¿¤ê¤¹¤ë¤Î¤Ç /bin/bash ¤È»ØÄꤷ¤Æ¤ª¤¯¤Î¤¬ÌµÆñ
> chmod +x abc.sh
> ./abc.sh
COUNT=1
echo $COUNT echo ${COUNT}
#!/bin/bash VAL1=1023 VAL2=1024 echo "$VAL1 + 10 : $(( $VAL1 + 10 ))" echo "$VAL1 - 10 : $(( $VAL1 - 10 ))" echo "$VAL1 * 10 : $(( $VAL1 * 10 ))" echo "$VAL1 / 10 : $(( $VAL1 / 10 ))" echo "$VAL1 % 10 : $(( $VAL1 % 10 ))" echo "$VAL1 & 255 : $(( $VAL1 & 255 ))" echo "$VAL1 | 255 : $(( $VAL1 | 255 ))" echo "$VAL1 ^ 255 : $(( $VAL1 ^ 255 ))" echo "NOT $VAL1 : $(( !$VAL1 ))" echo "NOR $VAL1 : $(( ~$VAL1 ))" echo "$VAL1>$VAL2 ? : $(( $VAL1 > $VAL2 ))" echo "$VAL1<$VAL2 ? : $(( $VAL1 < $VAL2 ))" echo "$VAL1>=$VAL2 ? : $(( $VAL1 >= $VAL2 ))" echo "$VAL1<=$VAL2 ? : $(( $VAL1 <= $VAL2 ))" echo "$VAL1==$VAL2 ? : $(( $VAL1 == $VAL2 ))" echo "$VAL1!=$VAL2 ? : $(( $VAL1 != $VAL2 ))" echo "$VAL1<$VAL2 && $VAL1!=$VAL2 ? : $(( $VAL1 < $VAL2 && $VAL1 != $VAL2 ))" echo "$VAL1>$VAL2 && $VAL1!=$VAL2 ? : $(( $VAL1 > $VAL2 && $VAL1 != $VAL2 ))" echo "$VAL1<$VAL2 || $VAL1>$VAL2 ? : $(( $VAL1 < $VAL2 || $VAL1 > $VAL2 ))" LITERATURE="ABCDEFGABCDEFGHIJKLMN" echo "ORIGINAL : $LITERATURE" echo "REPLACE FIRST 'BCD': ${LITERATURE/BCD/XXX}" echo "REPLACE ALL 'BCD' : ${LITERATURE//BCD/XXX}" echo "CUT FORMER (FIRST FIND PATTERN): ${LITERATURE#*D}" echo "CUT FORMER (LONGEST PATTERN) : ${LITERATURE##*D}" echo "CUT LATTER (FIRST FIND PATTERN): ${LITERATURE%D*}" echo "CUT LATTER (LONGEST PATTERN) : ${LITERATURE%%D*}"
> ./variable.sh 1023 + 10 : 1033 1023 - 10 : 1013 1023 * 10 : 10230 1023 / 10 : 102 1023 % 10 : 3 1023 & 255 : 255 1023 | 255 : 1023 1023 ^ 255 : 768 NOT 1023 : 0 NOR 1023 : -1024 1023>1024 ? : 0 1023<1024 ? : 1 1023>=1024 ? : 0 1023<=1024 ? : 1 1023==1024 ? : 0 1023!=1024 ? : 1 1023<1024 && 1023!=1024 ? : 1 1023>1024 && 1023!=1024 ? : 0 1023<1024 || 1023>1024 ? : 1 ORIGINAL : ABCDEFGABCDEFGHIJKLMN REPLACE FIRST 'BCD': AXXXEFGABCDEFGHIJKLMN REPLACE ALL 'BCD' : AXXXEFGAXXXEFGHIJKLMN CUT FORMER (FIRST FIND PATTERN): EFGABCDEFGHIJKLMN CUT FORMER (LONGEST PATTERN) : EFGHIJKLMN CUT LATTER (FIRST FIND PATTERN): ABCDEFGABC CUT LATTER (LONGEST PATTERN) : ABC
#!/bin/bash echo "TOTAL LENGTH OF ARGS : $#" CNT=1 echo "ARG(0)=$0" until [ -z $1 ] do echo "ARG($CNT)=$1 (OTHER ARGS : $#)" CNT=$((CNT+1)) shift done
> ./arg.sh arg1 arg2 arg3 TOTAL LENGTH OF ARGS : 3 ARG(0)=./arg.sh ARG(1)=arg1 (OTHER ARGS : 3) ARG(2)=arg2 (OTHER ARGS : 2) ARG(3)=arg3 (OTHER ARGS : 1)
#!/bin/bash GLOBAL_VAL=123 ¡ func1(){ echo "----------FUNC1 START----------" ¢ echo "FUNC1 ARG(0)=$0" £ echo "FUNC1 ARG(1)=$1" ¤ echo "FUNC1 ARG(2)=$2" echo "GLOBAL_VAL =$GLOBAL_VAL" GLOBAL_VAL=321 PRIVATE_VAL=987 echo "----------FUNC1 END ----------" ¥ return 0 } echo "---------------SHELL START---------------" ¦ if func1 A1 A2 then echo "FUNC1 RETURNED TRUE" else echo "FUNC2 RETURNED FALSE" fi § echo "SHELL ARG(0)=$0" ¨ echo "SHELL ARG(1)=$1" © echo "SHELL ARG(2)=$2" ª echo "GLOBAL VALUE =$GLOBAL_VAL" « echo "PRIVATE VALUE=$PRIVATE_VAL" echo "--------------SHELL END ---------------"
> ./function.sh S1 S2 ---------------SHELL START--------------- ----------FUNC1 START---------- ¢ FUNC1 ARG(0)=./function.sh £ FUNC1 ARG(1)=A1 ¤ FUNC1 ARG(2)=A2 GLOBAL_VAL =123 ----------FUNC1 END ---------- ¦ FUNC1 RETURNED TRUE § SHELL ARG(0)=./function.sh ¨ SHELL ARG(1)=S1 © SHELL ARG(2)=S2 ª GLOBAL VALUE =321 « PRIVATE VALUE=987 --------------SHELL END ---------------
#!/bin/bash sqrt(){ return $(($1*$1)) } isPositive(){ if [ $1 -gt 0 ] then return 0 else return 1 fi } isNegative(){ if [ $1 -lt 0 ] then return 0 else return 1 fi }
#!/bin/sh . common.sh sqrt $1 echo "SQRT($1)=$?" if isPositive $2 then echo "$2 is Positive" else echo "$2 is not Positive" fi if isNegative $3 then echo "$3 is Negative" else echo "$3 is not Negative" fi
> ./calc.sh 2 3 4 SQRT(2)=4 3 is Positive 4 is not Negative
#/bin/bash exit $1
> ./exit.sh 0 > echo $? 0
> ./exit.sh 1 > echo $? 1
> ./exit.sh -1 > echo $? 255
> ./exit.sh 1023 > echo $? 255
if ¥³¥Þ¥ó¥É then ¥³¥Þ¥ó¥ÉÀ®¸ù»þ(ÊÖÃÍ0¤Î»þ)¤Î½èÍý else ¥³¥Þ¥ó¥É¼ºÇÔ»þ(ÊÖÃÍ0°Ê³°¤Î»þ)¤Î½èÍý fi
if ¥³¥Þ¥ó¥É then : else ¥³¥Þ¥ó¥É¼ºÇÔ»þ(ÊÖÃÍ0°Ê³°¤Î»þ)¤Î½èÍý fi
while ¥³¥Þ¥ó¥É do ¥³¥Þ¥ó¥ÉÊÖÃͤ¬¿¿(0)¤Î»þ¤Î½èÍý done
until ¥³¥Þ¥ó¥É do ¥³¥Þ¥ó¥ÉÊÖÃͤ¬µ¶(0°Ê³°)¤Î»þ¤Î½èÍý done
#!/bin/bash COUNT=1 ### WHILE LOOP ### while [ $COUNT -le 10 ] do echo -n "$COUNT ," COUNT=$COUNT + 1 done echo WHILE LOOP END : COUNT = $COUNT ### UNTIL LOOP ### until [ $COUNT -le 0 ] do echo -n "$COUNT ," COUNT=`expr $COUNT - 1` done echo UNTIL LOOP END : COUNT = $COUNT
> ./while.sh 1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 ,WHILE LOOP END : COUNT = 11 11 ,10 ,9 ,8 ,7 ,6 ,5 ,4 ,3 ,2 ,1 ,UNTIL LOOP END : COUNT = 0
sed -e '/s/hoge/geho/g' foo.txt | while read line; do echo $line done
while read line; do echo $line done < file.txt
while read line; do echo $line done <<END hoge geho END
[~]$ which [ /bin/[
[~]$ ./cmp.sh $ARG= "test -n $ARG" is 0 "test -z $ARG" is 0 "test -n "$ARG"" is 1 "test -z "$ARG"" is 0 [~]$ ./cmp.sh aiueo $ARG=aiueo "test -n $ARG" is 0 "test -z $ARG" is 1 "test -n "$ARG"" is 0 "test -z "$ARG"" is 1(0:TRUE / 1:FALSE) C¸À¸ì¤ÈµÕ
#!/bin/bash WORD="I'm AHO." if [[ $WORD =~ ^I.*[.]$ ]] then echo "\"${WORD}\"¤Ï¡¢A¤Ç¤Ï¤¸¤Þ¤ê.¤Ç½ª¤ï¤ê¤Þ¤¹" fi if [[ $WORD =~ AHO ]] then echo "\"${WORD}\"¤Ï¡¢AHO ¤ËÉôʬ°ìÃפ·¤Þ¤¹" fi if [[ ! $WORD =~ BAKA ]] then echo "\"${WORD}\"¤Ï¡¢BAKA ¤ËÉôʬ°ìÃפ·¤Þ¤»¤ó" fi case $WORD in "I'm "?*) echo "\"${WORD}\"¤Ï¡¢\"I'm\"¤Ê¤ó¤È¤«¤Ç¤¹" ;; "You're "?*) echo "\"${WORD}\"¤Ï¡¢\"You're\"¤Ê¤ó¤È¤«¤Ç¤¹" ;; *) echo "Not Match" ;; esac
[~]$ ./regex.sh "I'm AHO."¤Ï¡¢A¤Ç¤Ï¤¸¤Þ¤ê.¤Ç½ª¤ï¤ê¤Þ¤¹ "I'm AHO."¤Ï¡¢AHO ¤ËÉôʬ°ìÃפ·¤Þ¤¹ "I'm AHO."¤Ï¡¢BAKA ¤ËÉôʬ°ìÃפ·¤Þ¤»¤ó "I'm AHO."¤Ï¡¢"I'm"¤Ê¤ó¤È¤«¤Ç¤¹
# !/bin/bash for str in abc def ghi jkl mno pqr stu vwx yz do echo $str done
> ./for.sh abc def ghi jkl mno pqr stu vwx yz
# !/bin/bash for file in *.txt do echo "$file --> /tmp/$file" cp $file /tmp/$file done
> ./for.sh gol.txt --> /tmp/gol.txt log.txt --> /tmp/log.txt
#!/bin/bash until [ -z $1 ] do case $1 in -v) shift ; VERBOSE=ON ;; -src) shift ; SRC=$1 ; shift ;; -dest) shift ; DEST=$1 ; shift ;; *) echo "Usage case.sh [-v] [-src] [SOURCE FILE] [-dest] [DEST_FILE]" exit -1 ;; esac done echo "VERBOSE_MODE =${VERBOSE:=OFF}" echo "SOURCE_FILE = ${SRC:=UNDEF}" echo "DEST_FILE = ${DEST:=UNDEF}"
> ./case.sh -src abc.dat -dest def.txt VERBOSE_MODE =OFF SOURCE_FILE = abc.dat DEST_FILE = def.txt
> bash -x ./case.sh -src abc.dat -dest def.txt + '[' -z -src ']' + case $1 in + shift + SRC=abc.dat + shift + '[' -z -dest ']' + case $1 in + shift + DEST=def.txt + shift + '[' -z ']' + echo 'VERBOSE_MODE =OFF' VERBOSE_MODE =OFF + echo 'SOURCE_FILE = abc.dat' SOURCE_FILE = abc.dat + echo 'DEST_FILE = def.txt' DEST_FILE = def.txt
#!/bin/bash
MEM="-Xms16m -Xmx1024m -XX:MaxPermSize=256m"
JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk/
PATH=$JAVA_HOME/bin
CLASSPATH=
LIB_DIR=/opt/myApp/lib
ls ${JAR_DIR} | while read line
do
CLASSPATH=$CLASSPATH:$line
done
echo $CLASSPATH
java -cp $CLASSPATH $MEM com.snail.myApp
#!/bin/bash
MEM="-Xms16m -Xmx1024m -XX:MaxPermSize=256m"
JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk/
PATH=$JAVA_HOME/bin
CLASSPATH=
LIB_DIR=/opt/myApp/lib
for line in ${JAR_DIR}/*.jar
do
CLASSPATH=$CLASSPATH:$line
done
echo $CLASSPATH
java -cp $CLASSPATH $MEM com.snail.myApp
ls ${JAR_DIR} >| /tmp/jars while read line do CLASSPATH=$CLASSPATH:$line done < /tmp/jars rm /tmp/jars¤È¤«¤â¤Ç¤¤ë¤±¤É
#!/bin/bash
HOME=$(cd $(dirname $0) && pwd)
echo $HOME
¼Â¹Ô¥×¥í¥°¥é¥à̾($0) ¤Î¥Ç¥£¥ì¥¯¥È¥ê¤Ë cd ¤·¤Æ¡¢pwd ¤Ç¤½¤ÎÀäÂХǥ£¥ì¥¯¥È¥ê̾¤òÆÀ¤ë¡£$() Æâ¤Ç cd ¤·¤Æ¤¤¤ë¤Î¤Ç¡¢Shell Script ¤Î¥«¥ì¥ó¥È¥Ç¥£¥ì¥¯¥È¥ê¤ÏÊѤï¤é¤Ê¤¤[~]$ ./example.sh /Users/Atsushi