求一个简单脚本,作为入门

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
zack_fly
帖子: 74
注册时间: 2009-10-15 16:23
联系:

求一个简单脚本,作为入门

#1

帖子 zack_fly » 2011-04-17 22:59

没有接触过shell脚本,最近打算学,因为感觉比较有意思,而且方便使用。
我希望有下面这样的一个脚本:

我刚刚装了xampp,使用的相应的命令是sudo /opt/lampp/lampp 后面参数目前只关心start, stop和restart

我希望在终端输入sudo xampp start,就相当于sudo /opt/lampp/lampp start

求这个脚本的代码。另外,求教Shell脚本的入门建议和学习资料。我目前到目标仅仅是通过脚本,简化操作,使用ubuntu更灵活方便(另,我有编程基础)
欢迎访问Gevin的博客 http://blog.igevin.info
头像
Ubuntu与Linux
帖子: 1211
注册时间: 2010-06-09 19:57

Re: 求一个简单脚本,作为入门

#2

帖子 Ubuntu与Linux » 2011-04-17 23:23

对/opt/lampp/lampp 建立个链接,把链接复制到/usr/bin里面,重命名为xampp
头像
ebok
帖子: 852
注册时间: 2008-02-15 0:09

Re: 求一个简单脚本,作为入门

#3

帖子 ebok » 2011-04-18 0:54

命令别名或软链接
Somebody think they are full of niubility, so they play a zhuangbility, but only reflect their shability.
头像
HelloAndroid
帖子: 156
注册时间: 2010-10-17 18:23

Re: 求一个简单脚本,作为入门

#4

帖子 HelloAndroid » 2011-04-18 1:00

2l正解! :em11 :em11
用起来还是蛮舒服的!
生命在于折腾!
为什么这个论坛复旦的人很少!!
fnan
帖子: 919
注册时间: 2009-07-01 22:04

Re: 求一个简单脚本,作为入门

#5

帖子 fnan » 2011-04-19 6:08

支持3楼,别名是首选。

关于shell入门,自己的经验是先折腾grep, find, sed 这3个命令, 然后awk,流程控制,函数等, 命令的话撞着那个学那个,有编程基础很简单,多写脚本培养shell思维,就是用shell思维实现一般的编程算法,那些教程闷死了,自己是在论坛找些题目去做,做不出再翻教程, man指令,不知道这方法别人合不合适, 3月一日开始学写脚本,自己对进度还满意。
bash不如perl精妙,学不到lisp的皮毛,远不够c++强悍,不过可以用。
chengmoYS
帖子: 125
注册时间: 2007-10-22 22:40

Re: 求一个简单脚本,作为入门

#6

帖子 chengmoYS » 2011-04-19 9:16

推荐参看shell教程 teach yourself shell programming in 24 hours
头像
link_01
帖子: 1024
注册时间: 2008-11-05 13:24

Re: 求一个简单脚本,作为入门

#7

帖子 link_01 » 2011-04-19 11:03

[bash]
#!/bin/sh
# 迅雷的base64地址互换
# 判断开头的是“http”还是“thunder”,然后使用StringBase64转换。
base64() {
if [ $# -eq 1 ]; then
temp="AA${1}ZZ"
s2=`../go/StringBase64 $temp 2>/dev/null`
echo "thunder://${s2}"
elif [ $# -eq 2 ]; then
temp=`echo $2 | sed 's/^thunder:\/\///'`
s2=`../go/StringBase64 -d $temp 2>/dev/null`
echo $s2 | sed 's/^AA//' |sed 's/ZZ$//'
fi
}

if echo $1 | grep -q '^http' 2>/dev/null; then
base64 $1
elif echo $1 | grep -q '^thunder' 2>/dev/null; then
base64 -d $1
else
exit 1
fi
[/bash]
笔记
-------------------------------------
http://blog.163.com/wqt_1101
头像
zack_fly
帖子: 74
注册时间: 2009-10-15 16:23
联系:

Re: 求一个简单脚本,作为入门

#8

帖子 zack_fly » 2011-05-16 20:35

多谢各位啦!
欢迎访问Gevin的博客 http://blog.igevin.info
回复