简体   繁体   English

shell中的变量如何使用?

[英]How to use variables in shell?

Having a simple script like this, which should convert minutes to seconds有一个像这样的简单脚本,它应该将分钟转换为秒

#!bin/bash
echo 'input_minutes'
read x
time="expr $x '*' 60"
echo $time

When run after entering a number (5), it outputs an expression "expr $x '*' 60" instead of a product(300).在输入数字 (5) 后运行时,它会输出表达式"expr $x '*' 60"而不是 product(300)。 What could be the reason?可能是什么原因?

You didn't execute the expression, instead you created a string.您没有执行表达式,而是创建了一个字符串。 Try it like this:试试这样:

time=$(expr $x '*' 60)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM