简体   繁体   English

Android Shell脚本阅读

[英]Android shell script read

I'm trying to get a shell script to take values. 我正在尝试获取一个shell脚本以获取值。 What I currently have is: 我目前拥有的是:

#!/system/bin/sh
echo "Enter the page numbers"
read page_no_first;
read page_no_final;
#
echo $page_no_first
echo $page_no_final

The echos are simply there for debug, and the problem is that they display as blanks. 回声只是用于调试,而问题在于它们显示为空白。

The terminal results are as such: 最终结果如下:

scriptname
Enter the page numbers
1
1
5
5

Verbatim. 逐字。 That is the echo commands simply produce two empty lines. 也就是说,echo命令仅产生两个空行。

I've found a sort of work around, and another related problem: 我发现了一种解决方法,以及另一个相关问题:

#!/system/bin/sh
echo "Enter the page numbers"
read page_no_first -s
read page_no_final -s
#
echo $page_no_first
echo $page_no_final

This should give me the read without it repeating the input. 这应该给我阅读,而无需重复输入。 Instead, what it gives me is: 相反,它给我的是:

scriptname
Enter the page numbers
1
1
: is readonlyriptname[3]: read: -s
3
3
: is readonlyriptname[3]: read: -s
1
3

Ironically, this successfully writes the numbers to the variables, however, it a) does not give me a silent read, and b) gives me some funny error. 具有讽刺意味的是,这成功地将数字写入了变量,但是,它a)不会给我一个静默读取,b)给了我一些有趣的错误。 Googling it doesn't help, since it's too vague. 谷歌搜索没有帮助,因为它太模糊了。

Any help? 有什么帮助吗?

This work as expected (at least as I think it should): 这项工作符合预期(至少按照我的想法):

#! /system/bin/sh

echo "Enter the page numbers"
echo -n "First: "
read page_no_first
echo -n "Last: "
read page_no_last
echo "First: $page_no_first   Last: $page_no_last"

on android 4.2 在Android 4.2上

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

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