bash 编程中遇到的问题:
首先,建议在linux 下编写bash,如果你要用windows 编写bash 的话,那么,你要特别注意几个问题:
第一:编码问题,用utf-8 编码,
第二:换行符问题,windows是回车换行(CRLF)结尾,linux 是换行(LF)结尾
第三:使用utf-8无bom。
这三点是在windows 下编写bash 的注意事项。
至于语法,我这边就不多做讲了,我也是初次编写bash,语法基本没啥说的,有一年编程基础的都能看懂。
http://pan.baidu.com/s/1o6C1rnW,
分享一个bash 片段吧。这是从maven 私服 nexus 中获取的,其功能就是获取绝对路径
# Resolve the true real path without any sym links.
CHANGED=true
while [ "X$CHANGED" != "X" ]
do
# Change spaces to ":" so the tokens can be parsed.
SAFESCRIPT=`echo $SCRIPT | sed -e ‘s; ;:;g‘`
#echo "script path is:[$SCRIPT]"
#echo "SAFESCRIPT path is:[$SAFESCRIPT]"
# Get the real path to this script, resolving any symbolic links
TOKENS=`echo $SAFESCRIPT | sed -e ‘s;/; ;g‘`
#echo "TOKENS path is:[$TOKENS]"
REALPATH=
for C in $TOKENS; do
# Change any ":" in the token back to a space.
C=`echo $C | sed -e ‘s;:; ;g‘`
REALPATH="$REALPATH/$C"
# If REALPATH is a sym link, resolve it. Loop for nested links.
while [ -h "$REALPATH" ] ; do
LS="`ls -ld "$REALPATH"`"
LINK="`expr "$LS" : ‘.*-> \(.*\)$‘`"
if expr "$LINK" : ‘/.*‘ > /dev/null; then
# LINK is absolute.
REALPATH="$LINK"
else
# LINK is relative.
REALPATH="`dirname "$REALPATH"`""/$LINK"
fi
done
done
if [ "$REALPATH" = "$SCRIPT" ]
then
CHANGED=""
else
SCRIPT="$REALPATH"
fi
done
# Change the current directory to the location of the script
cd "`dirname "$REALPATH"`"
REALDIR=`pwd`
bash 基础语法_下载链接:http://yun.baidu.com/share/link?shareid=2510088394&uk=4043945255
bash 的几个示例:
1、自动打包。http://pan.baidu.com/s/1bniv5W7
2、linux 服务运行 java shell。http://yun.baidu.com/share/link?shareid=3338177448&uk=4043945255
3、linux 运行java 命令,包含环境变量的配置,jvm 参数的设置。http://yun.baidu.com/share/link?shareid=3334612191&uk=4043945255
&& 再来个windows 运行java 命令,跟3一样的功能http://yun.baidu.com/share/link?shareid=3335077510&uk=4043945255