linux - Basic if else scripting
问题描述
I hope you all are doing great. I am new to Linux shell scripting. I am trying to learn basic shell scripting and i started with with if else condition and I am stuck in it since a week. I have read as many articles as I could but I am not understanding what is the problem here. I know this must a very basic for you guys but please help me :)
Here is the script that I wrote
#!/bin/sh
count=102
if [$count -gt 100]
then
echo "$count is greater than 100"
else
echo "$count is less than 100"
fi
When I execute this script, I am getting below error.
./count.sh: line 5: [102: command not found 102 is less than 100
*I also tried taking user input not just with integer but with string also, still getting the same error. please help :)
Thank you in advance
解决方案
you need to provide space after [
and before ]
. For e.g
[ $count -gt 100 ]
Sample code :
count=102
if [ $count -gt 100 ]
then
echo "$count is greater than 100"
else
echo "$count is less than 100"
fi
推荐阅读
- go - 如何循环直到 *ipconn.Read() 读取了 go 中发送给它的所有数据
- html - 显示具有可变白色间距的文本?
- python-3.x - 一旦条件相同的循环完成第一次迭代,就试图从一开始就重新开始迭代循环
- c# - Blazor 启动项目设置错误
- angular - 单个模块中的角度组模块引用
- amazon-web-services - 将 AWS 简单电子邮件服务文件复制到另一个账户中的 S3 存储桶
- c++ - 使用 FFmpeg 初始化 mkv 的输出文件
- php - 在值中包含换行符
- javascript - 递减计数器有奇怪的行为
- php - 如何在 PHP 中获取一年中某一天的日期?