02. 26.

从网上找到的一段代码,对于学习bash的同学理解case想必很有帮助

#!/bin/bash
####################################################
# Program:
# File operation
# 1.) Open file 2.) Display file 3.) Edit file 4.) Delete file
# History:
# 2006/11/03 BianYuan First release
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
echo “———————————”
echo “List of item to operate file -”
echo “———————————”
echo “1). Open a file -”
echo “2). Display a file -”
echo “3). Edit a file -”
echo “4). Delete a file -”
echo “———————————”
read select
case $select in
1)
echo “do open file operation”
;;
2)
echo “do display a file operation”
;;
3)
echo “do edit a file operation”
;;
4)
echo “do delete a file operation”
;;
*)
echo “There is nothing to do!”
exit 1
;;
esac


07. 13.

Bash While Loop Example – Bash While 循环实例

Q. How do I use bash while loop to repeat certain task under Linux / UNIX operating system?
A. Bash while loop is a control flow statement that allows code or commands to be executed repeatedly based on a given condition. For example, run echo command 5 times or read text file line by line or evaluate the options passed on the command line for a script.
while loop syntax
阅读全文 »


05. 28.

如果你习惯了linux下的bash, 可能sh会叫你有点不舒服, 只是可能, 其实习惯了就好, 关于freebsd下bash的安装和配置, 写了一个简单的步骤:

Freebsd默认安装之后用户的shell是sh,如果都已经习惯了使用bash。通过下面的步骤可以配置用户来使用bash作为shell。

1. 安装bash。 cd /usr/ports/shells/bash; make install clean
这样安装完之后,bash会被安装在/usr/local/bin/目录下面。
2. 在/bin目录下面做一个符号连接。
ln -s /usr/local/bin/bash /bin/bash

3. 修改 /etc/shells文件,将bash增加进去,
添加一行:/bin/bash 就可以了

阅读全文 »