尧图网站建设 尧图网络
  • 首页
  • 关于我们
  • 服务项目
  • 案例展示
  • 建站流程
  • 资讯中心
  • 联系我们
首页/资讯中心/详情

Shell - What does : do?

Shell - What does : do?
📅 发布时间:2026/6/20 13:13:28
Shell - What does ":" do?

In shell (especially POSIX shells like sh, bash, dash, zsh), : is a builtin command called the null command.

What it does

  • Does nothing

  • Always succeeds (returns exit status 0)

:
echo $?
# 0

Why it’s useful

Even though it does nothing, : is surprisingly handy.


1. Placeholder in scripts

When syntax requires a command but you don’t want to do anything yet:

if condition; then:
fi

2. Infinite loops

Common idiom:

while :; doecho "Running..."sleep 1
done

(: always succeeds, so the loop never ends.)


3. Default action in conditionals

When you want to explicitly do nothing:

case "$var" inyes) echo "Yes" ;;no)  echo "No" ;;*)   : ;;
esac

4. Variable expansion with side effects

Often used to safely trigger parameter expansion:

: "${VAR:=default}"
  • Sets VAR to default if it’s unset or empty

  • No output, no side effects besides assignment


5. Redirecting without running a command

Since : does nothing, it’s useful with redirections:

: > file.txt        # truncate or create file
: >> logfile.log    # append (touch-like)

6. Alternative to true

: is faster and more portable than calling /bin/true:

while :; do ...; done

Summary

Feature:
Type Shell builtin
Effect Does nothing
Exit status Always 0
Common uses Loops, placeholders, parameter expansion, redirection

 

相关新闻

  • 轻松部署Qwen3-8B:结合ComfyUI打造可视化交互界面
  • 收藏必备!2025年企业AI Agent落地的四大主流路径深度解析,小白到程序员都能看懂
  • git commit规范在vLLM项目开发中的最佳实践

最新新闻

  • 【Claude】Extra inputs are not permitted 错误:代理剥离 Beta 标头的解决方案 bug报错已解决
  • 2026 年 6 月帝舵中国区官方售后全新升级:售后体系优化调整,全国门店最新地址、官方咨询电话一站式完整汇总指南 - 亨得利中国服务中心
  • 反无人机 —— 三层区域划分
  • TSN网络部署实战:VCAP流处理与Q-in-Q配置详解
  • 计算机Python毕设实战-基于 Django 的胶济铁路博物馆管理系统的设计与实现基于 B/S 架构的胶济铁路博物馆运维管理系统的设计与实现【完整源码+LW+部署说明+演示视频,全bao一条龙等】
  • Adobe-GenP技术深度解析:通用补丁机制与批量激活实现原理

日新闻

  • 信任的进化:技术实现详解——如何用JavaScript构建博弈论模拟器
  • Terrakube自定义工作流:如何集成OPA、Infracost等工具扩展IaC能力
  • grunt-concurrent快速入门:5分钟学会并行运行Grunt任务

周新闻

  • 3步解锁iOS设备:applera1n激活锁绕过完全指南
  • 39 2026 人工智能证书终极盘点,普通人选 AI 证书可以从这些方向入手
  • Redis 暴露公网有多危险?从端口检查到补救步骤

月新闻

  • 【总结】入门篇:50句话让你记住架构核心概念
  • WeChatMsg技术方案解析:实现Mac微信数据自主管理的完整解决方案
  • WeChatMsg:革新性微信数据备份方案,打造你的专属数字记忆库

关于尧图

  • 公司简介
  • 团队介绍
  • 企业文化
  • 荣誉资质

服务项目

  • 定制开发
  • 电商建站
  • UI 设计
  • 运维服务

快速链接

  • 案例展示
  • 建站流程
  • 常见问题
  • 资讯中心

联系方式

  • 📍北京市朝阳区互联网产业园 A 座 10 层
  • 📞400-888-8888
  • ✉️contact@rkmt.cn
  • 🕐周一至周日 9:00-21:00

© 2024 北京尧图网络科技有限公司 版权所有 | 京 ICP 备 XXXXXXXX 号