免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6394 | 回复: 3
打印 上一主题 下一主题

[系统管理] 请问一下 下面脚本中的 "${1#-}" != "$1" 的1#是什么意思? [复制链接]

论坛徽章:
5
程序设计版块每日发帖之星
日期:2016-04-15 06:20:00每日论坛发贴之星
日期:2016-04-15 06:20:0015-16赛季CBA联赛之八一
日期:2016-07-08 09:20:28操作系统版块每日发帖之星
日期:2016-08-03 06:20:002016科比退役纪念章
日期:2016-10-30 13:59:12
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2020-09-16 13:50 |只看该作者 |倒序浏览
#!/bin/sh
set -e

# first arg is `-f` or `--some-option`
# or first arg is `something.conf`
if [ "${1#-}" != "$1" ] || [ "${1%.conf}" != "$1" ]; then
        set -- redis-server "$@"
fi

# allow the container to be started with `--user`
if [ "$1" = 'redis-server' -a "$(id -u)" = '0' ]; then
        find . \! -user redis -exec chown redis '{}' +
        exec gosu redis "$0" "$@"
fi

exec "$@"

论坛徽章:
60
20周年集字徽章-20	
日期:2020-10-28 14:04:3015-16赛季CBA联赛之北京
日期:2016-07-06 15:42:0715-16赛季CBA联赛之同曦
日期:2016-06-12 10:38:0915-16赛季CBA联赛之佛山
日期:2016-05-27 11:54:56黄金圣斗士
日期:2015-12-02 11:44:35白银圣斗士
日期:2015-11-25 14:32:43白银圣斗士
日期:2015-11-23 12:53:352015亚冠之布里斯班狮吼
日期:2015-10-21 16:55:482015亚冠之首尔
日期:2015-09-01 16:46:052015亚冠之德黑兰石油
日期:2015-08-31 11:39:192015亚冠之萨济拖拉机
日期:2015-08-28 21:06:5315-16赛季CBA联赛之广东
日期:2016-07-12 14:58:53
2 [报告]
发表于 2020-09-17 14:49 |只看该作者

语法:
${var#Pattern}, ${var##Pattern}
Remove from $var the shortest/longest part of $Pattern that matches the front end of $var.



${var%Pattern}, ${var%%Pattern}
Remove from $var the shortest/longest part of $Pattern that matches the back end of $var.

[root@hk tmp]# x=a-b+c-d+e-f+g
[root@hk tmp]#
[root@hk tmp]# echo ${x#*-}   #从左到右,删除最短匹配
b+c-d+e-f+g
[root@hk tmp]#
[root@hk tmp]# echo ${x##*-} #从左到右,删除最长匹配
f+g
[root@hk tmp]#
[root@hk tmp]# echo ${x%-*}  #从右到左,删除最短匹配
a-b+c-d+e
[root@hk tmp]#
[root@hk tmp]# echo ${x%%-*} #从右到左,删除最长匹配
a
[root@hk tmp]#

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
3 [报告]
发表于 2020-09-30 09:38 |只看该作者
回复 1# 274920831


参考:Bash中的字符串处理
http://bbs.chinaunix.net/thread-746472-1-1.html

论坛徽章:
59
2015七夕节徽章
日期:2015-08-24 11:17:25ChinaUnix专家徽章
日期:2015-07-20 09:19:30每周论坛发贴之星
日期:2015-07-20 09:19:42ChinaUnix元老
日期:2015-07-20 11:04:38荣誉版主
日期:2015-07-20 11:05:19巳蛇
日期:2015-07-20 11:05:26CU十二周年纪念徽章
日期:2015-07-20 11:05:27IT运维版块每日发帖之星
日期:2015-07-20 11:05:34操作系统版块每日发帖之星
日期:2015-07-20 11:05:36程序设计版块每日发帖之星
日期:2015-07-20 11:05:40数据库技术版块每日发帖之星
日期:2015-07-20 11:05:432015年辞旧岁徽章
日期:2015-07-20 11:05:44
4 [报告]
发表于 2020-10-28 12:24 |只看该作者
又学习一招。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP