新足迹

 找回密码
 注册

精华好帖回顾

· 今天我那没有长焦的雨后外拍作业 (2010-5-24) kur7 · DIY ----- 让家的每一个角落更漂亮方便(床板系列之1) (2010-8-15) coleclark999
· 交流一下养蚕宝宝的心得 (多图和养护知识不断添加中) (2016-8-27) 爱吃荤的猫 · 看图学习DIY修理淋浴漏水,更换开关 (2010-3-22) 5years
Advertisement
Advertisement
查看: 1473|回复: 7

请教个bash script问题 [复制链接]

发表于 2013-4-25 22:54 |显示全部楼层
此文章由 水星浪子 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 水星浪子 所有!转贴必须注明作者、出处和本声明,并保持内容完整
while [ "${1:0:1}" == "-" ]
do

这个while是判断啥啊?
Advertisement
Advertisement

发表于 2013-4-26 00:09 |显示全部楼层
此文章由 CES 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 CES 所有!转贴必须注明作者、出处和本声明,并保持内容完整
${1:0:1} expands to a substring of $1 starting at character 0 and getting 1 character

http://forums.devshed.com/script ... -1-0-1t-153253.html

评分

参与人数 1积分 +2 收起 理由
水星浪子 + 2 感谢分享

查看全部评分

发表于 2013-4-26 00:11 |显示全部楼层
此文章由 bulaohu 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 bulaohu 所有!转贴必须注明作者、出处和本声明,并保持内容完整
猛一看还以为是那个fork bomb ;)

发表于 2013-4-26 00:13 |显示全部楼层
此文章由 seabookf_91 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 seabookf_91 所有!转贴必须注明作者、出处和本声明,并保持内容完整
${1:0:1} expands to a substring of $1 starting at character 0 and getting 1 character. So the 0 is the starting index of the substring and the 2nd 1 is the number of characters in the substring.
当地一个参数以 “-” 开始的时候, 做 // ...

评分

参与人数 1积分 +2 收起 理由
水星浪子 + 2

查看全部评分

发表于 2013-4-29 16:14 |显示全部楼层
此文章由 nali 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 nali 所有!转贴必须注明作者、出处和本声明,并保持内容完整
Advanced Bash-Scripting Guide 第780页和 第125页
http://www.tldp.org/LDP/abs/abs-guide.pdf

${string:position:length}
Extract $length characters substring from $string at $position [zero-indexed, first character is at position 0]
  1. Table B-5. String Operations
  2. Expression Meaning
  3. ${#string} Length of $string
  4. ${string:position} Extract substring from $string at $position
  5. ${string:position:length} Extract $length characters substring from $string at $position [zero-indexed, first character is at position 0]
  6. ${string#substring} Strip shortest match of $substring from front of $string
  7. ${string##substring} Strip longest match of $substring from front of $string
  8. ${string%substring} Strip shortest match of $substring from back of $string
  9. ${string%%substring} Strip longest match of $substring from back of $string
  10. ${string/substring/replacement} Replace first match of $substring with $replacement
  11. ${string//substring/replacement} Replace all matches of $substring with $replacement
  12. ${string/#substring/replacement} If $substring matches front end of $string, substitute $replacement for $substring
  13. ${string/%substring/replacement} If $substring matches back end of $string, substitute $replacement for $substring expr match "$string" '$substring' Length of matching $substring* at beginning of $string
复制代码

发表于 2013-4-29 16:16 |显示全部楼层
此文章由 红烧鸡翅 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 红烧鸡翅 所有!转贴必须注明作者、出处和本声明,并保持内容完整
好生僻
Advertisement
Advertisement

发表于 2013-4-29 22:04 |显示全部楼层
此文章由 audreamer 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 audreamer 所有!转贴必须注明作者、出处和本声明,并保持内容完整
可读性太差了,越牛的人,写的代码应该user-friendly。

发表于 2013-4-29 22:36 |显示全部楼层
此文章由 水星浪子 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 水星浪子 所有!转贴必须注明作者、出处和本声明,并保持内容完整
谢谢各位回复。
这个句子的用意是查看参数如果是以横杠打头的就判断下是不是 --hide-ok这个参数,否则忽略
while [ "${1:0:1}" == "-" ]
do
    case $1 in
        --hide-ok)
            option_hide_ok=yes
            options="$options --hide-ok"
            shift
            ;;
        *)
            echo "Ignoring unknown option $1"
            echo
            shift
            ;;
    esac
done

发表回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Advertisement
Advertisement
返回顶部