简体   繁体   中英

Android shell script read

I'm trying to get a shell script to take values. 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.

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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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