Shell

#prompt
> echo $PS1
#searches manpage names and descriptions for regular expressions suplied as arguments.
> apropos music

> stat -c '%A %h %U %G %s %y %n' /tmp/studio
> find /tmp/ -name test.cpp -printf '%m %n %u %g %t %p'

#I won't pay $5 for coffee.
> echo 'I won'\''t pay $5 for coffee.'

#/etc/shells
> chsh

#GigaHerz = 1.93
> printf '%10.10s = %4.2f\n' 'GigaHerz' 1.92735

#1 STDOUT, 2 STDERR
> command 1> messages.out 2> messages.err
# command 1> messages.out 2>&1
> command &> messages.out

# braces { } used to group commands together
# with the braces used for grouping, any other changes that you make will be made to your current shell instance.
# The subshell is almost identical to the current shell's environment, but after it returns, its changes are never made to main shell instance.
> { comand1; command2; } > all.out
> (comand1; command2) > all.out

# tee - read from STDIN and write to STDOUT & files
> command1 | tee /out.1 | command2

# $() encloses a command that is run in a subshell, and newlines in the output are replaced with $IFS, which is a space by default.
> rm $(find . -name '*.class')

Shorten this:
if [ $result = 1 ]; then
echo "Result is 1; excellent."
exit 0
else
echo "Uh-oh, ummm, RUN AWAY!"
exit 120
fi

into this:
[ $result =1 ] \
&& { echo "Result is 1; excellent."; exit 0; } \
|| { echo "Uh-oh, ummm, RUN AWAY!"; exit 120; }

standard output is buffered but standard error is unbuffered.

| or ! means do it anyway. Eg. in vi, q!. Without a !, the editor will complain if you havenot save your changes.
echo something >| output.file

<< says that we want to create such a temporary input source, and the following is just an arbitrary string to act as the terminator of the temporary input.

grep $1 <<\EOF #grep $1 <<'EOF'
...
EOF

$? will be set with a non-zero value if the command fails. But be aware that you only get one shot at reading the exit status.
somecommand;
if (($?)) ; then ...; else ...; fi
somecommand && ... || ...

# run cmd as deamon and ignore the SIGHUP
nohup cmd &

PROG=echo
HI=hello
$PROG $HI

for SCRIPT in /path/to/scripts/dir/*
do
if [ -f $SCRIPT -a -x $SCRIPT ]
then
$SCRIPT
fi
done

set, env, export -p : seeing all variable values.

$@, $* refers to all the arguments supplied on the command line.
"$*" gives the entire list inside one set of quotes, but "$@" returns not one string but a list of quoted strings, one for each argument.

for param in "$@"
do
...
done

${#} gives the number of parameters the script was invoked.
${#VAR} gives the length of the value in the variable VAR.
${VAR#alt} does a certain kind of substitution.

# the :- operator, says that if $1 is not set or is null then it will use what follows as the value.
VAR1=${1:-"defaultValue"}

# the := operator, is the same as :- operator. But the := will do an assignment as well as return the value on the right of the operator. The :- will do half of that -- it just returns the value but doesn't do the assignment.
cd ${HOME:=/tmp} # HOME eq. /tmp

#:? giving an error message for unset parameters
VAR1=${1:?"error message"}

inside ${ ... } Action taken
name:number:number Substring starting character, length
#name Return the length of the string
name#pattern Remove (shortest) front-anchored pattern
name##pattern Remove (longest) front-anchored pattern
name%pattern Remove (shortest) rear-anchored pattern
name%%pattern Remove (longest) rear-anchored pattern
name/pattern/string Replace first occurrence
name//pattern/string Replace all occurrences

array_1=(first second third)
${array_1[2]} # $array_1 eq. ${array_1[0]}

a=$((2**8)) #eq. 256
let a/=5
# / is integer arithmetic, not floating point. Eg, 2/3 eq. 0.

if [ $# -lt 3]
then
...
fi

or alternatively:

if (( $# < 3))
then
...
elif (( $# > 3 ))
then
...
else
...
fi

if test $# -lt 3
then
...
fi

Option Description
-b File is block special device (for files like /dev/hda1)
-c File is character special (for files like /dev/tty)
-d File is a directory
-e File exists
-f File is a regular file
-g File has its set-group-ID bit set
-h File is a symbolic link (same as -L)
-G File is owned by the effective group ID
-k File has its sticky bit set
-L File is a symbolic link (same as -h)
-O File is owned by the effective user ID
-p File is a named pipe
-r File is readable
-s File has a size greater than zero
-S File is a socket
-u File has its set-user-ID bit set
-w File is writable
-x File is executable

FILE1 -nt FILE2
ls newer than (it checks the modification date)
FILE1 -ot FILE2
ls older than
FILE1 -ef FILE2
Have the same device and inode numbers (identical file, even if pointed to by different links)

if [ -r $FILE -a -w $FILE ]
# use parentheses to get the proper precedence, as in a and (b or c), but be sure to escape their special meaning from the shell by putting a backslash before each or by quoting each parenthesis.
if [ -r "$FN" -a \( -f "$FN" -o -p "$FN" \) ]
# don't count on short circuits in your conditionals.
# it is important to put quotes around the "$VAR" expression because without them you syntax could be disturbed by odd user input. (like sql injection)

# the -eq operator for numeric comparisons and the equality primary = (or ==) for string comparisons.
Numeric String Meaning
-lt < Less than
-le <= Less than or equal to
-gt > Greater than
-ge >= Greater than or equal to
-eq =, == Equal to
-ne != Not equal to

# Testing with Regular Expressions:
# Ludwig Van Beethoven - 05 - "Leonore" Overture, No. 2 Op. 72.ogg
if [[ "$CDTRACK" =~ "([[:alpha:][:blank:]]*)- ([:digit:]*) - (.*)$" ]]
then
echo Track ${BASH_REMATCH[2]} is ${BASH_REMATCH[3]}
mv "$CDTRACK" "Track${BASH_REMATCH[2]}"
fi
# For built-in array variable $BASH_REMATCH, the zeroth element ($BASH_REMATCH[0]) is the entire string matched by the regular expression. Any subexpressions are available as $BASH_REMATCH[1], #BASH_REMATCH[2], and so on.
#Matches are case-sensitive, but you may use shopt -s nocasematch (available in bash versions 3.1+) to change that. This option affects case and [[ commands.

while (( COUNT < MAX ))
do
...
done

while [ -z "$LOCKFILE" ][ $TAG == \? ]
then
echo $FN
rm -rf "$FN"
fi
done

svn status mysrc | grep '^?' | cut -c8- | \
while read FN; do echo "$FN"; rm -rf "$FN"; done

for (( i=0, j=0 ; i+j < 10 ; i++, j++ ))
do
echo $((i*j))
done

for i in 1 2 3 4 5 6 7 8 9 10 # for i in $(seq 1 1 10)
do
echo $i
done

seq 1.0 .01 1.1 | \ #preferred approach for a really long sequence, as it can run the seq command in parallel with the while.
while read fp
do
echo $fp; other stuff too
done

case $FN in
*.gif) gif2png $FN
;;
*.png) pngOK $FN
;;
*.jpg) jpg2gif $FN
;;
*.tif | *.TIFF) tif2jpg $FN #Use |, a vertical bar meaning logical OR.
;;
*) printf "File not supported: %s" $FN
;;
esac

# get the content between line 555 and line 666 of file1.
sed -n "555,666"p file1

Well, that was then and this is now.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
内容介绍 项目结构: Controller层:使用Spring MVC来处理用户请求,负责将请求分发到相应的业务逻辑层,并将数据传递给视图层进行展示。Controller层通常包含控制器类,这些类通过注解如@Controller、@RequestMapping等标记,负责处理HTTP请求并返回响应。 Service层:Spring的核心部分,用于处理业务逻辑。Service层通过接口和实现类的方式,将业务逻辑与具体的实现细节分离。常见的注解有@Service和@Transactional,后者用于管理事务。 DAO层:使用MyBatis来实现数据持久化,DAO层与数据库直接交互,执行CRUD操作。MyBatis通过XML映射文件或注解的方式,将SQL语句与Java对象绑定,实现高效的数据访问。 Spring整合: Spring核心配置:包括Spring的IOC容器配置,管理Service和DAO层的Bean。配置文件通常包括applicationContext.xml或采用Java配置类。 事务管理:通过Spring的声明式事务管理,简化了事务的处理,确保数据一致性和完整性。 Spring MVC整合: 视图解析器:配置Spring MVC的视图解析器,将逻辑视图名解析为具体的JSP或其他类型的视图。 拦截器:通过配置Spring MVC的拦截器,处理请求的预处理和后处理,常用于权限验证、日志记录等功能。 MyBatis整合: 数据源配置:配置数据库连接池(如Druid或C3P0),确保应用可以高效地访问数据库。 SQL映射文件:使用MyBatis的XML文件或注解配置,将SQL语句与Java对象映射,支持复杂的查询、插入、更新和删除操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值