[英]How to use a properties file that contains numbers properties in shell
This is my first question on StackOverflow. 这是我对StackOverflow的第一个问题。 I am pretty sure it would have been answered already (it is a pretty dumb question, I think, as I just started to learn Linux scripting), but I did'nt succeed to find an answer yet.
我很确定它已经回答了(我刚开始学习Linux脚本时,这是一个非常愚蠢的问题),但是我没有成功找到答案。
Sorry for that. 抱歉
Here is my problem: I try to use in a shell a number given in a property file, I have an error because the number is not taken "as it is". 这是我的问题:我尝试在外壳中使用属性文件中给出的数字,但由于该数字未按“原样”使用而出现错误。
I have a prop.properties file : 我有一个prop.properties文件:
sleepTimeBeforeLoop=10
and a test.sh shell : 和一个test.sh shell:
#!/bin/sh
. prop.properties
echo "time="$sleepTimeBeforeLoop
sleep $sleepTimeBeforeLoop
When I launch test.sh I have the following Output : 当启动test.sh时,我有以下输出 :
time=10
sleep: invalid time interval `10\r'
Try `sleep --help' for more information.
What I understand is that my properties files was correctly sourced, but that the property was taken as a string, with some special character to indicate the end of the line, or whatever. 我了解的是我的属性文件是正确来源的,但是该属性被当作一个字符串使用,带有一些特殊字符来指示行尾或其他内容。
How can I do to take only the "10" value? 如何只取“ 10”值?
Thank you in advance for your answer. 预先感谢您的答复。
This is line endings issue / make sure your script files are terminated by \\n
(the unix way) eg. 这是行尾问题/请确保您的脚本文件以
\\n
(Unix方式)终止。 write it in UNIX text editor or use a windows one capable of saving in "unix style" 在UNIX文本编辑器中编写它,或使用能够以“ unix样式”保存的Windows窗口
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.