#!/bin/sh a="rilakkuma" cat << "EOL" [animal] ${a} EOL
[animal] ${a}
# exit 2 | exit 1 | exit 0
# echo $? 0
# echo ${PIPESTATUS[@]} 2 1 0
# echo ${PIPESTATUS[0]} 2
script_dir=$(cd $(dirname $BASH_SOURCE); pwd)
function func() { local arg1=$1 eval $arg1='代入するよ' # 変数名='代入するよ' に展開される } func test echo $test
function func() { local arg1=$1 local list=() list+=("hoge") list+=("fuga") eval $arg=\(${hoge[@]}\) }
{ time pwd; } 2>&1
( time pwd; ) 2>&1
ret=$(( time pwd; ) 2>&1)
$ A=AAA $ ( A=BBB ) $ echo $A AAA
$ ls Nothing_path || ( echo ERROR; echo ERROR2 ) ls: cannot access 'Nothing_path': No such file or directory ERROR ERROR2
[[ 1 -lt 2 && 2 -lt 3 ]] [[ abc == a* ]] [[ a2 =~ a[0-9] ]]
VAR=`command 2>&1`
VAR=`command 2>&1 1>/dev/null`
#/bin/bash a="ABC DEFG" echo $a echo "$a"
ABC DEFG ABC DEFG
find . -name \*~ -print0 | xargs -0 rm
find . -name \*~ -print0 | xargs -0 -I{} mv {} /var/tmp
# var="/my/path/dir/test.dat" # echo ${var#*/} # my/path/dir/test.dat
# var="/my/path/dir/test.dat" # echo ${var##*/} # test.dat
# var="abcdef abcdef xyz" # echo ${var/abc/XXX} # XXXdef abcdef xyz
# var="abcdef abcdef xyz" # echo ${var//abc/XXX} # XXXdef XXXdef xyz
# var="1aaaa,2bbbb,3cccc" # arry=(${var//,/ }) # echo ${arry[1]} # 2bbbb
% ls ~shishimaru a.xml memo.txt
ls `bash -c "echo ~shishimaru"`
local cmd=$1 local password=$2 echo $cmd expect -c " spawn ${cmd} expect { "*password:*" { send $password\r\n; interact } eof { exit } } exit "
expect -c " set timeout -1 spawn ${cmd} expect { "*password:*" { send $password\r\n; interact } eof { exit } } exit "
echo 10000000 | awk '{printf "%\047d\n",$1}' 10,000,000
echo $RANDOM
echo $(($RANDOM % 101))
date +'%Y%m%d-%H%M%S.%3N'
date +'%Y%m%d-%H%M%S.%6N'
date +'%Y%m%d-%H%M%S.%N'
[myapp@app-system ~]$ date Sun Feb 16 21:40:50 CST 2014 [myapp@app-system ~]$ date +'%s' 1392608453 [myapp@app-system ~]$ date -d "Sun Feb 16 21:40:50" +'%s' 1392608450
[ptestuser@testserver18]$ for i in {1..10}; do; echo $i; done 1 2 3 4 5 6 7 8 9 10
tr ',' '\n' < filename
sed ':loop; N; $!b loop; ;s/,/\n/g' filename
tr -d '\n' < filename
if [ 1 -eq 1 -a 0 -eq 0 ]; then echo true fi
if [ 1 -eq 1 ] && [ "A" = "C" -o "B" = "B" ]; then echo true fi
if [[ ( A == 1) && ( B == 2 && ( C == 3 || D == 4 ) ) ]]; then echo true fi
#!/bin/sh A=0.1 B=0.2 X=`echo "$A > $B" | bc` ### $A > $B が真なら 1、 偽なら 0 if [ $X -eq 1 ] ;then ###bashは真は0、偽は1なのでややこしい。 echo $A is large else echo $B is large fi
[root@testserver18 TAR_ABIS]# expr length "1234567890" 10
echo "a,b,c" | awk -F"," '{print $1, $2, $3}' echo "a,b,c" | awk 'BEGIN {FS=","} {print $1, $2, $3}' # 出力結果 a b c
echo "a,b,c" | awk 'BEGIN {RS=","} {print $1, $2, $3}' # 出力結果 a b c
echo "a b c" | awk 'BEGIN {OFS=","} {print $1, $2, $3}' # 出力結果 a,b,c
echo "a b c" | awk 'BEGIN {ORS="\n\n"} {print $1, $2, $3}' # レコードの区切りを改行2個 # 出力結果 a b c
unitx_time = mktime(Y m d H M S)
echo "10/28/2016 02:27:59" | awk '{ split($1, date, "/") split($2, time, ":") tstamp = sprintf("%s %s %s %s %s %s", date[3], date[1], date[2], time[1], time[2], time[3]) utime_jtc = mktime(tstamp) + 9 * 3600 print (strftime("%Y/%m/%d %H:%M:%S", utime_jtc), $3) }'
2016/10/28 11:27:59
#!/bin/bash a=10 echo "aaa" | awk '{print $1, '$a'}' [ptestuser@testserver18]$ sh test.sh aaa 10
a=10 b=20 echo "aaa" | awk -v val=$a -v val2=$b '{print $1, val}'
shishimaru@myserver% echo 123456789 | awk '{printf("%\047d\n", $1)}' 123,456,789
rpm -q --scripts <PKG_NAME> rpm -qp --scripts <PKG_FILE>
cd /var/lib/rpm cp -p __db.00* /tmp
rm -f __db.00*
rpm --rebuilddb
rpm -e --ignoresize test-unit
rpm2cpio test-unit-3.2.3-0.x86_64.rpm | cpio -id
rpm2cpio test-unit-3.2.3-0.x86_64.rpm | cpio --list
top -b -c -d1 -n3 > top.log
top's Config File (Linux processes with windows) Id:i, Mode_altscr=0, Mode_irixps=1, Delay_time=1.0, Curwin=0 Def fieldscur=\¨³´»½ÀÄ·º¹Å&')*+,-./0125¶8<>?ABCFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghij winflags=193972, sortindx=18, maxtasks=0, graph_cpus=0, graph_mems=0 summclr=1, msgsclr=1, headclr=3, taskclr=1 Job fieldscur=\¦¹·º(³´Ä»½@<§Å)*+,-./012568>?ABCFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghij winflags=193844, sortindx=0, maxtasks=0, graph_cpus=0, graph_mems=0 summclr=6, msgsclr=6, headclr=7, taskclr=6 Mem fieldscur=\º»<½¾¿ÀÁMBNÃD34·Å&'()*+,-./0125689FGHIJKLOPQRSTUVWXYZ[\]^_`abcdefghij winflags=193844, sortindx=21, maxtasks=0, graph_cpus=0, graph_mems=0 summclr=5, msgsclr=5, headclr=4, taskclr=5 Usr fieldscur=\¦§¨ª°¹·ºÄÅ)+,-./1234568;<=>?@ABCFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghij winflags=193844, sortindx=3, maxtasks=0, graph_cpus=0, graph_mems=0 summclr=3, msgsclr=3, headclr=2, taskclr=3 Fixed_widest=0, Summ_mscale=0, Task_mscale=0, Zero_suppress=0
shishimaru@myserver% printf "%5d %d %d\n" 10 200 3000 00010 200 3000
rsync -ur DIR root@myserver:/home/myapp/DATA_FILES
command 2>&1 | tee log
usleep 100000
#!/bin/bash -eux -o pipefail -o errtrace
tail -F server/default/log/tm-info.log | grep --line-buffered -v "PERF" | grep "EXTRACT" | sed 's/\[.*CATEGORY===INFO//g'
rsyncコマンドでコピーする
local list=() list+=("hoge")
local NewArray=() local Array=()
Array+=("hoge1") Array+=("hoge2") NewArray=("${Array[@]}")
function func() { declare -n arg_list=$1 for i in ${arg_list[@]} do echo $i done } list=("hoge" "huga") func list # $をつけずに渡す
for i in ${list[@]} do
case文 case $val in true|false)
$ sed '/hoge2/a hoge-add' text.txt hoge hoge1 hoge2 hoge-add hoge3 hoge4
sed 's/before/after/n'
sed 's/before/after/ng'
command | tac | rev | sed 's/before/after/ng' | tac | rev
sed -e\ 's/before/after/n'{,,,}
$ echo -e "1:aaaa\n2:bbbb\n3:cccc" 1:aaaa 2:bbbb 3:cccc $ echo -e "1:aaaa\n2:bbbb\n3:cccc" | sed '/2:/s/:/@/' 1:aaaa 2@bbbb 3:cccc
$ echo -e "1:aaaa\n2:bbbb\n3:cccc" 1:aaaa 2:bbbb 3:cccc $ echo -e "1:aaaa\n2:bbbb\n3:cccc" | sed '/2:/!s/:/@/' 1@aaaa 2:bbbb 3@cccc
[appuser@testserver11 logs]$ sed -n "/ready to deSerial from inputStream../,+1p" catalina.out 2016-08-24 16:16:12,075 [http-nio-8080-exec-13] DEBUG [appserver.InquiryServlet] - ready to deSerial from inputStream.. 2016-08-24 16:16:12,079 [http-nio-8080-exec-13] DEBUG [appserver.InquiryServlet] - ready to call inquiry with parameter PBTestJobRequest.. 2016-08-24 16:16:13,460 [http-nio-8080-exec-1] DEBUG [appserver.InquiryServlet] - ready to deSerial from inputStream.. 2016-08-24 16:16:13,464 [http-nio-8080-exec-1] DEBUG [appserver.InquiryServlet] - ready to call inquiry with parameter PBTestJobReque
$ echo -e "aaaa\n bbbb\n cccc\naaaa\n bbbb\naaaa\n bbbb" | sed 1,/bbbb/s/bbbb/dddd/ aaaa dddd cccc aaaa bbbb aaaa bbbb
$ echo -e "aaaa\n bbbb\n cccc\naaaa\n bbbb\naaaa\n bbbb" | sed /cccc/,/bbbb/s/aaaa/eeee/ aaaa bbbb cccc eeee bbbb aaaa bbbb
cat config/parameter.xml | sed '/<KEYWORD>/,/<\/KEYWORD>/{/<rolled>/,/<\/rolled>/s/enroll/identify/}'
cat config/parameter.xml | \ sed '/<KEYWORD>/,/<\/KEYWORD>/{/<extract>/,/<\/extract>/{/<rolled>/,/<\/rolled>/s/enroll/ennnn/}}' | grep enn
sed -e '開始行,削除行d' ファイル名