linux - Bash如何将linux命令的结果存储在变量中?
问题描述
我正在尝试将计算机的温度存储在变量中。我试过这个但它不起作用:
#!/bin/bash
temp = cat "/sys/class/thermal/thermal_zone0/temp"
echo "$temp"
我也试过这个:
#!/bin/bash
temp = $(cat "/sys/class/thermal/thermal_zone0/temp")
echo "$temp"
但没有任何效果,它总是说
./temp.sh: line 2: temp: command not found
解决方案
空间很关键!这工作正常:
# NO space around `=`
temp=$(cat "/sys/class/thermal/thermal_zone0/temp")
echo "$temp"
推荐阅读
- python - Pyspark 使用正则表达式在第一次出现时拆分
- haskell - 计算给定输入类型的函数返回类型
- sql - 从匹配特定条件的大表中选择(稀疏)数据点
- php - 生产网站弹出sandbox.paypal支付窗口,而不仅仅是paypal.com支付窗口
- python - 访问被拒绝运行 Jupyter Notebook (Anaconda)
- c++ - Qt C++ 在表之间拖动 QHeaderView
- vb6 - 代码含义——visual basic 6类文件
- mysql - sql复杂连接
- android - NativeScript loadStarted WebView 事件不会在 Android 上触发
- powershell - Powershell - 使用所有者的邮件地址获取统一组