ls -t

ls -t: Sort and display in time stamp order.

[vagrant@localhost tests]$ touch index.php
[vagrant@localhost tests]$ ls -t
index.php backup beforeinstall.sh codedeploy
[vagrant@localhost tests]$ ls
backup beforeinstall.sh codedeploy index.php

なるほど~
[vagrant@localhost tests]$ ls -l | tail -n+2
drwxrwxr-x 3 vagrant vagrant 4096 3月 17 20:41 2019 backup
-rwxr-xr-x 1 vagrant vagrant 422 3月 17 20:41 2019 beforeinstall.sh
drwxr-xr-x 3 vagrant vagrant 4096 3月 17 11:04 2019 codedeploy
-rw-rw-r– 1 vagrant vagrant 0 3月 18 08:36 2019 index.php

If not specified, 10 lines from the last line will be displayed, but with the -n option, the specified number of lines will be output.

[vagrant@localhost tests]$ ls -t | tail -n+1
index.php
backup
beforeinstall.sh
codedeploy
[vagrant@localhost tests]$ ls -t | tail -n+4
codedeploy
[vagrant@localhost tests]$ ls -t | tail -n+3
beforeinstall.sh
codedeploy
[vagrant@localhost tests]$ ls -t | tail -n+2
backup
beforeinstall.sh
codedeploy

にゃるほどー

shell loop(for), function, +α

#!/bin/sh

for var in 0 1 2 3 4
do
	echo $var
done

[vagrant@localhost tests]$ sed -i ‘s/\r//’ test.sh
[vagrant@localhost tests]$ ./test.sh
0
1
2
3
4

{0..5}とも書ける。」

#!/bin/sh

for var in {0..5}
do
	echo $var
done

function

#!/bin/sh

MyFunction(){
	echo "display function"
}
MyParamFunc(){
	echo "parm1:$1 param2:$2"
}

MyFunction
MyParamFunc 5 4

[vagrant@localhost tests]$ sed -i ‘s/\r//’ test.sh
[vagrant@localhost tests]$ ./test.sh
display function
parm1:5 param2:4

with linux command

#!/bin/sh

index=1
for file in *.txt
do
	mv "$file" "mytxt${index}.txt"
	index=`expr $index + 1`
done

[vagrant@localhost tests]$ sed -i ‘s/\r//’ test.sh
[vagrant@localhost tests]$ ./test.sh

すげええええええええええええええええええええええええ

shell while

#!/bin/sh

a=0
while [ $a -lt 5 ]
do
	echo $a
	a=`expr $a + 1`
done

[vagrant@localhost tests]$ sed -i ‘s/\r//’ test.sh
[vagrant@localhost tests]$ ./test.sh
0
1
2
3
4

‘と`の違いで手古摺った.

#!/bin/sh

a=0
until [ ! $a -lt 5 ]
do
	echo $a
	a=`expr $a + 1`
done

shell case

#!/bin/sh

DRINK="beer"
case "$DRINK" in
	"beer") echo "this is beer"
	;;
	"juice") echo "that is juice"
	;;
	"coak") echo "Do not drink it"
	;;
esac

[vagrant@localhost tests]$ sed -i ‘s/\r//’ test.sh
[vagrant@localhost tests]$ ./test.sh
this is beer

esacとか、使い慣れてないなー

shell if

#!/bin/sh

if [ "$1" -gt "$2" ]
then
	echo "1番目の引数が2番目の引数より大きい"
elif [ "$1" -eq "$2" ]
then
	echo "1番目の引数と2番目の引数は同じです"
else
	echo "1番目の引数が2番目の引数より小さい"
fi

[vagrant@localhost tests]$ sed -i ‘s/\r//’ test.sh
[vagrant@localhost tests]$ ./test.sh 5 4
1番目の引数が2番目の引数より大きい

shell special variable

Variable Function
$0 script name
Access $1 ~ $9 arguments, $1 for the first argument, $2 for the second argument

$ # number of arguments given to the script
$ * treat all arguments together as one
$ @ Thread all arguments as separate
$? End value of the last executed command (0 is success, 1 is failure)
$$ Process ID of this shell script
$! last executed background process ID

#!/bin/sh

echo "\$0 (スクリプト名): $0"
echo "\$1 (1番目の引数): $1"
echo "\$2 (2番目の引数): $2"
echo "\$# (引数の数): $#"
echo "\"\$*\": \"$*\""
echo "\"\$@\": \"$@\""
VAR="exit値は0になるはずです"
echo $?

[vagrant@localhost tests]$ sed -i ‘s/\r//’ test.sh
[vagrant@localhost tests]$ ./test.sh
$0 (スクリプト名): ./test.sh
$1 (1番目の引数): 
$2 (2番目の引数): 
$# (引数の数): 0
“$*”: “”
“$@”: “”
0

shell variables

Can use single-byte alphanumeric characers and underscores as variable name. a to z, A to Z, 0 to 9 and _.
When giving a value to a variable, write = without leading and trailing blanks. If it is a string, enclose it in “.
Put $ before the variable name when accessing the variable. or put $ and enclose the variable in {}.
Only one value can be stored in one variable.
Use readonly to not overwrite the value of the variable. Variables can be deleted by unset. (You can not delete the readonly variable.)

#!/bin/sh

var="yukijirushi"
var2="coffee"
echo "I'm drinking $var2"

[vagrant@localhost tests]$ sed -i ‘s/\r//’ test.sh
[vagrant@localhost tests]$ ./test.sh
I’m drinking coffee

なるほど。

#!/bin/sh

var="yukijirushi"
var2="coffee"
echo "I'm drinking $var2"

var2="traditional test"
echo ${var2}

[vagrant@localhost tests]$ sed -i ‘s/\r//’ test.sh
[vagrant@localhost tests]$ ./test.sh
I’m drinking coffee
traditional test

ここまでは簡単

sed -i ‘s/\r//’

Shell script is simply to execute Unix command etc. side by side. It is responsible for when to execute what instruction and what condition, read file contents, and write log file.

#!/bin/sh

echo "Hello, World!"

[vagrant@localhost tests]$ chmod 755 test.sh
[vagrant@localhost tests]$ ./test.sh
-bash: ./test.sh: /bin/sh^M: bad interpreter: そのようなファイルやディレクトリはありません
[vagrant@localhost tests]$ sed -i ‘s/\r//’ test.sh
sed: -e 表現 #1, 文字数 1: 未知のコマンドです: 「▒」
[vagrant@localhost tests]$ ./test.sh
-bash: ./test.sh: /bin/sh^M: bad interpreter: そのようなファイルやディレクトリはありません
[vagrant@localhost tests]$ sed -i ‘s/\r//’ test.sh
[vagrant@localhost tests]$ ./test.sh
Hello, World!

#!/bin/sh


# コメントです。
read NAME
echo "Hello, $NAME!"

あれ、コマンドラインが止まる? なんでだろう。。

What is mysql data type of Oracle “NUMBER”?

Oracle data type: NUMBER
The “NUMBER” data type stores fixed and floating point numbers. It can store virtually any numerical value. If your system is running Oracle Database, portability between systems is guaranteed with up to 38 digits of precision.

The NUMBER column can contain the following numbers:

A positive number in the range 1 x 10 – 130 to 9.99 … 9x 10125

Oracle guarantees the portability of numbers with the precision of 38 digits or less. When specifying numeric fields, it is better to specify precision and scale.

MySQL Data type
BIG INT:NUMBER (19, 0)
INT:NUMBER(10,0)
MEDIUMINT:NUMBER(7, 0)
NUMERIC:NUMBER
SMALLINT:NUMBER(5,0)
TINYINT:NUMBER(3,0)
YEAR:NUMBER

primary keyのIDでnumberを使われていれば、intでいいでしょうね。