簡體   English   中英

Android Shell腳本閱讀

[英]Android shell script read

我正在嘗試獲取一個shell腳本以獲取值。 我目前擁有的是:

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

回聲只是用於調試,而問題在於它們顯示為空白。

最終結果如下:

scriptname
Enter the page numbers
1
1
5
5

逐字。 也就是說,echo命令僅產生兩個空行。

我發現了一種解決方法,以及另一個相關問題:

#!/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

這應該給我閱讀,而無需重復輸入。 相反,它給我的是:

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

具有諷刺意味的是,這成功地將數字寫入了變量,但是,它a)不會給我一個靜默讀取,b)給了我一些有趣的錯誤。 谷歌搜索沒有幫助,因為它太模糊了。

有什么幫助嗎?

這項工作符合預期(至少按照我的想法):

#! /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"

在Android 4.2上

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM